Skip to content

Commit

Permalink
don't leak fds into subprocesses
Browse files Browse the repository at this point in the history
Patch from Antoine Labour <piman@chromium.org>, (hacky) test by me.
  • Loading branch information
evmar committed Oct 31, 2011
1 parent a621299 commit bb52198
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions misc/inherited-fds.ninja
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This build file prints out a list of open file descriptors in
# Ninja subprocesses, to help verify we don't accidentally leak
# any.

# Because one fd leak was in the code managing multiple subprocesses,
# this test brings up multiple subprocesses and then dumps the fd
# table of the last one.

# Use like: ./ninja -f misc/inherited-fds.ninja

rule sleep
command = sleep 10000

rule dump
command = sleep 1; ls -l /proc/self/fd; exit 1

build all: phony a b c d e

build a: sleep
build b: sleep
build c: sleep
build d: sleep
build e: dump
1 change: 1 addition & 0 deletions src/subprocess.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) {
if (pipe(output_pipe) < 0)
Fatal("pipe: %s", strerror(errno));
fd_ = output_pipe[0];
SetCloseOnExec(fd_);

pid_ = fork();
if (pid_ < 0)
Expand Down

0 comments on commit bb52198

Please sign in to comment.