From 6f0d05032410873bd5cdb573b998c7a7939d09b5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 5 Dec 2006 18:21:16 +0000 Subject: [PATCH] * 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. --- src/nix-worker/main.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/nix-worker/main.cc b/src/nix-worker/main.cc index a4372b4a5..a1e080933 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. */