Skip to content

Commit 4ac3067

Browse files
committed
build: add check for pipe2
pipe2 is already used unconditionally in start-stop-deamon for quite some time now. Ref: #626
1 parent 61231d5 commit 4ac3067

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ if cc.has_function('strlcpy', prefix: '#define _GNU_SOURCE\n#include <string.h>'
185185
add_project_arguments('-DHAVE_STRLCPY', language: 'c')
186186
endif
187187

188+
if not cc.has_function('pipe2', prefix: '#include <unistd.h>')
189+
if cc.has_function('pipe2', prefix: '#define _GNU_SOURCE\n#include <unistd.h>')
190+
add_project_arguments('-D_GNU_SOURCE', language: 'c')
191+
else
192+
error('pipe2() not supported')
193+
endif
194+
endif
195+
188196
incdir = include_directories('src/shared')
189197
einfo_incdir = include_directories('src/libeinfo')
190198
rc_incdir = include_directories('src/librc')

src/openrc-init/openrc-init.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
#include <stdlib.h>
2727
#include <string.h>
2828
#include <time.h>
29+
#include <fcntl.h>
2930
#include <unistd.h>
3031
#include <sys/stat.h>
3132
#include <sys/reboot.h>
3233
#include <sys/types.h>
3334
#include <sys/wait.h>
34-
#include <fcntl.h>
3535
#include <poll.h>
3636
#include <utmp.h>
3737

@@ -266,15 +266,8 @@ int main(int argc, char **argv)
266266
reexec = true;
267267

268268

269-
/* NOTE(NRK): consider using pipe2 maybe... */
270-
if (pipe(sigpipe) == -1) {
271-
perror("pipe");
272-
return 1;
273-
}
274-
if (fcntl(sigpipe[0], F_SETFD, O_NONBLOCK | FD_CLOEXEC) == -1 ||
275-
fcntl(sigpipe[1], F_SETFD, O_NONBLOCK | FD_CLOEXEC) == -1)
276-
{
277-
perror("fcntl");
269+
if (pipe2(sigpipe, O_NONBLOCK | O_CLOEXEC) == -1) {
270+
perror("pipe2");
278271
return 1;
279272
}
280273

0 commit comments

Comments
 (0)