about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-12-05T18·21+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-12-05T18·21+0000
commit6f0d05032410873bd5cdb573b998c7a7939d09b5 (patch)
tree6ce0e1c578f6681c868d20f59b01b79e3f6117ea /src
parent4c1c37d0b6f4f8e7331b359617d7071c5e6e42fb (diff)
* Tricky: child processes should not send data to the client since
  that might mess up the protocol.  And besides, the socket file
  descriptor is probably closed.

Diffstat (limited to 'src')
-rw-r--r--src/nix-worker/main.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/nix-worker/main.cc b/src/nix-worker/main.cc
index a4372b4a56c2..a1e0809331d2 100644
--- a/src/nix-worker/main.cc
+++ b/src/nix-worker/main.cc
@@ -29,6 +29,8 @@ static FdSource from(STDIN_FILENO);
 static FdSink to(STDOUT_FILENO);
 
 bool canSendStderr;
+pid_t myPid;
+
 
 
 /* This function is called anytime we want to write something to
@@ -37,7 +39,11 @@ bool canSendStderr;
    socket. */
 static void tunnelStderr(const unsigned char * buf, size_t count)
 {
-    if (canSendStderr) {
+    /* Don't send the message to the client if we're a child of the
+       process handling the connection.  Otherwise we could screw up
+       the protocol.  It's up to the parent to redirect stderr and
+       send it to the client somehow (e.g., as in build.cc). */
+    if (canSendStderr && myPid == getpid()) {
         try {
             writeInt(STDERR_NEXT, to);
             writeString(string((char *) buf, count), to);
@@ -47,7 +53,8 @@ static void tunnelStderr(const unsigned char * buf, size_t count)
             canSendStderr = false;
             throw;
         }
-    }
+    } else
+        writeFull(STDERR_FILENO, buf, count);
 }
 
 
@@ -344,6 +351,7 @@ static void performOp(Source & from, Sink & to, unsigned int op)
 static void processConnection()
 {
     canSendStderr = false;
+    myPid = getpid();    
     writeToStderr = tunnelStderr;
 
     /* Allow us to receive SIGPOLL for events on the client socket. */