about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-02-03T14·20+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-02-03T14·20+0000
commit81de538e46c154267c4fb7e87cf6804aed63f3df (patch)
treee51207632ade8342015d007fcff6b80c7d75ecf3
parentb90daaaf6c1f52fe93f4f845da20b122cfea2936 (diff)
* Use setsid instead of setpgrp in child processes. This not only
  creates a new process group but also a new session.  New sessions
  have no controlling tty, so child processes like ssh cannot open
  /dev/tty (which is bad).

-rw-r--r--src/libstore/build.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 123248c17670..85c89f2c5a1a 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -276,17 +276,19 @@ void Goal::trace(const format & f)
 /* Common initialisation performed in child processes. */
 void commonChildInit(Pipe & logPipe)
 {
-    /* Put the child in a separate process group so that it doesn't
-       receive terminal signals. */
-    if (setpgid(0, 0) == -1)
-        throw SysError(format("setting process group"));
-
+    /* Put the child in a separate session (and thus a separate
+       process group) so that it has no controlling terminal (meaning
+       that e.g. ssh cannot open /dev/tty) and it doesn't receive
+       terminal signals. */
+    if (setsid() == -1)
+        throw SysError(format("creating a new session"));
+    
     /* Dup the write side of the logger pipe into stderr. */
     if (dup2(logPipe.writeSide, STDERR_FILENO) == -1)
         throw SysError("cannot pipe standard error into log file");
     logPipe.readSide.close();
             
-    /* Dup stderr to stdin. */
+    /* Dup stderr to stdout. */
     if (dup2(STDERR_FILENO, STDOUT_FILENO) == -1)
         throw SysError("cannot dup stderr into stdout");