]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Birdloop pipe is set O_CLOEXEC.
authorMaria Matejka <mq@ucw.cz>
Wed, 2 Oct 2024 17:02:53 +0000 (19:02 +0200)
committerMaria Matejka <mq@ucw.cz>
Sun, 23 Feb 2025 18:01:48 +0000 (19:01 +0100)
If we decide to exec something, we shouldn't pass along our intenal fds.

configure.ac
sysdep/unix/io-loop.c

index 814d59199265c5e2ba969be652fab3b0c3127031..b60100eb2a59869e2cf1499c595f38cbba140e3f 100644 (file)
@@ -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"
index b4ac55c0444a2a799c96a6abb5b204fd3dd3cabd..77caf6689f79ef5b27a6f041b84a2e368ce5b4aa 100644 (file)
@@ -4,6 +4,8 @@
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
 
+#define _GNU_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -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