DJ Delorie c55f31d
From d79fe162c009788888faaf0317253b6f0cac7092 Mon Sep 17 00:00:00 2001
DJ Delorie c55f31d
From: Kevin Buettner <kevinb@redhat.com>
DJ Delorie c55f31d
Date: Thu, 23 Apr 2020 17:05:34 -0400
DJ Delorie c55f31d
Subject: [SV 58232] Disable inheritance of jobserver FDs for recursive make
DJ Delorie c55f31d
DJ Delorie c55f31d
A parent make will invoke a sub-make with close-on-exec disabled for
DJ Delorie c55f31d
the jobserver pipe FDs.  Force close-on-exec to be to be enabled in
DJ Delorie c55f31d
the sub-make so the pipe is not always passed to child jobs.
DJ Delorie c55f31d
DJ Delorie c55f31d
I have a test case which, when invoked with a suitable -j switch,
DJ Delorie c55f31d
will hang if the recipe inherits the jobserver pipe.  This test case
DJ Delorie c55f31d
was inspired by a real world case in which testing GDB on Fedora
DJ Delorie c55f31d
would hang due to some poorly written test GDB cases having been
DJ Delorie c55f31d
passed the jobserver file descriptors.
DJ Delorie c55f31d
DJ Delorie c55f31d
* src/posixos.c (jobserver_parse_auth): Call fd_noinherit() for
DJ Delorie c55f31d
jobserver pipe descriptors.
DJ Delorie c55f31d
DJ Delorie c55f31d
Copyright-paperwork-exempt: yes
DJ Delorie c55f31d
DJ Delorie c55f31d
diff --git a/src/posixos.c b/src/posixos.c
DJ Delorie c55f31d
index 525f292c..eab175a4 100644
DJ Delorie c55f31d
--- a/src/posixos.c
DJ Delorie c55f31d
+++ b/src/posixos.c
DJ Delorie c55f31d
@@ -145,6 +145,11 @@ jobserver_parse_auth (const char *auth)
DJ Delorie c55f31d
   /* When using pselect() we want the read to be non-blocking.  */
DJ Delorie c55f31d
   set_blocking (job_fds[0], 0);
DJ Delorie c55f31d
 
DJ Delorie c55f31d
+  /* By default we don't send the job pipe FDs to our children.
DJ Delorie c55f31d
+     See jobserver_pre_child() and jobserver_post_child().  */
DJ Delorie c55f31d
+  fd_noinherit (job_fds[0]);
DJ Delorie c55f31d
+  fd_noinherit (job_fds[1]);
DJ Delorie c55f31d
+
DJ Delorie c55f31d
   return 1;
DJ Delorie c55f31d
 }
DJ Delorie c55f31d