diff options
author | Julien Tinnes <jln@chromium.org> | 2015-01-29 19:33:35 (GMT) |
---|---|---|
committer | Julien Tinnes <jln@chromium.org> | 2015-01-29 19:36:30 (GMT) |
commit | 7b34ee99cdd350511942c2d84fc36ce1696e1686 (patch) | |
tree | 6ced67e1bc4dbb3e7f48b381a426b50b4f3379f4 /src/subprocess-posix.cc | |
parent | 62458b6f19dd134d2a4a38ff81e368c8b7e5605d (diff) | |
download | Ninja-7b34ee99cdd350511942c2d84fc36ce1696e1686.zip Ninja-7b34ee99cdd350511942c2d84fc36ce1696e1686.tar.gz Ninja-7b34ee99cdd350511942c2d84fc36ce1696e1686.tar.bz2 |
POSIX: detach background subprocesses from terminal.
Put background subprocesses (i.e. subprocesses with no access
to the console) in their own session and detach them from the
terminal.
This fixes martine/ninja#909.
Diffstat (limited to 'src/subprocess-posix.cc')
-rw-r--r-- | src/subprocess-posix.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc index 40c9ae1..cc8bff6 100644 --- a/src/subprocess-posix.cc +++ b/src/subprocess-posix.cc @@ -80,8 +80,11 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) { break; if (!use_console_) { - // Put the child in its own process group, so ctrl-c won't reach it. - if (setpgid(0, 0) < 0) + // Put the child in its own session and process group. It will be + // detached from the current terminal and ctrl-c won't reach it. + // Since this process was just forked, it is not a process group leader + // and setsid() will succeed. + if (setsid() < 0) break; // Open /dev/null over stdin. |