summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2017-01-13 04:53:01 (GMT)
committerColin Cross <ccross@android.com>2017-01-13 04:59:31 (GMT)
commitdd2b587e289603127f30ea296e7751e4cf90fe7d (patch)
treec10059f621c47af4b26b27060dbd54a196b3cf5d
parenta36f96c0a5ae3b204065ac8560410104cefcfa2f (diff)
downloadNinja-dd2b587e289603127f30ea296e7751e4cf90fe7d.zip
Ninja-dd2b587e289603127f30ea296e7751e4cf90fe7d.tar.gz
Ninja-dd2b587e289603127f30ea296e7751e4cf90fe7d.tar.bz2
Close original pipe fd in subprocesses
Non-console subprocesses have the write end of a pipe connected to fds 1 and 2 for stdout and stderr, but they also have the it connected to whatever fd was assigned in the ninja process when the pipe was created. Add a call to posix_spawn_file_actions_addclose after the posix_spawn_file_actions_adddup2 calls to close the original fd once it has been dup'd to stdout and stderr. This fixes an issue seen in the Android build, where one of the subprocesses is used to start a background helper process. The background process attempts to close any inherited fds, but if ninja used a very large fd number due to a high parallelism count the background process would not close the fd and ninja would never consider the subprocess finished.
-rw-r--r--src/subprocess-posix.cc2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc
index f1f94e5..1de22c3 100644
--- a/src/subprocess-posix.cc
+++ b/src/subprocess-posix.cc
@@ -88,6 +88,8 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) {
Fatal("posix_spawn_file_actions_adddup2: %s", strerror(errno));
if (posix_spawn_file_actions_adddup2(&action, output_pipe[1], 2) != 0)
Fatal("posix_spawn_file_actions_adddup2: %s", strerror(errno));
+ if (posix_spawn_file_actions_addclose(&action, output_pipe[1]) != 0)
+ Fatal("posix_spawn_file_actions_addclose: %s", strerror(errno));
// In the console case, output_pipe is still inherited by the child and
// closed when the subprocess finishes, which then notifies ninja.
}