From 169677deeb14edbc2eecdd056924af85c6d512d8 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Wed, 2 Oct 2024 19:02:53 +0200 Subject: [PATCH] Birdloop pipe is set O_CLOEXEC. If we decide to exec something, we shouldn't pass along our intenal fds. --- configure.ac | 2 ++ sysdep/unix/io-loop.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index cf7e60cb..cf0a294e 100644 --- a/configure.ac +++ b/configure.ac @@ -281,6 +281,8 @@ sysdep_dirs="`sed <$sysdesc '/^Link: /!d;s/^Link: \(.*\)$/\1/' | tr '\012' ' '`" AC_MSG_RESULT([$sysdep_dirs]) AC_SUBST([sysdep_dirs]) +AC_CHECK_FUNCS([pipe2]) + if test "$with_iproutedir" = no ; then with_iproutedir= ; fi if test -n "$given_iproutedir" diff --git a/sysdep/unix/io-loop.c b/sysdep/unix/io-loop.c index b4ac55c0..77caf668 100644 --- a/sysdep/unix/io-loop.c +++ b/sysdep/unix/io-loop.c @@ -4,6 +4,8 @@ * Can be freely distributed and used under the terms of the GNU GPL. */ +#define _GNU_SOURCE + #include #include #include @@ -195,15 +197,22 @@ birdloop_in_this_thread(struct birdloop *loop) void pipe_new(struct pipe *p) { + int flags = O_NONBLOCK | O_CLOEXEC; +#if HAVE_PIPE2 + int rv = pipe2(p->fd, flags); + if (rv < 0) + die("pipe2: %m"); +#else int rv = pipe(p->fd); if (rv < 0) die("pipe: %m"); - if (fcntl(p->fd[0], F_SETFL, O_NONBLOCK) < 0) + if (fcntl(p->fd[0], F_SETFL, flags) < 0) die("fcntl(O_NONBLOCK): %m"); - if (fcntl(p->fd[1], F_SETFL, O_NONBLOCK) < 0) + if (fcntl(p->fd[1], F_SETFL, flags) < 0) die("fcntl(O_NONBLOCK): %m"); +#endif } void