nix-daemon: Simplify stderr handling

This commit is contained in:
Eelco Dolstra 2014-07-23 19:37:40 +02:00 committed by Ludovic Courtès
parent 766481d606
commit bb07dfe96f
2 changed files with 2 additions and 7 deletions

View File

@ -850,6 +850,7 @@ pid_t startProcess(std::function<void()> fun, const string & errorPrefix)
if (pid == -1) throw SysError("unable to fork"); if (pid == -1) throw SysError("unable to fork");
if (pid == 0) { if (pid == 0) {
_writeToStderr = defaultWriteToStderr;
try { try {
restoreAffinity(); restoreAffinity();
fun(); fun();

View File

@ -48,7 +48,6 @@ static FdSource from(STDIN_FILENO);
static FdSink to(STDOUT_FILENO); static FdSink to(STDOUT_FILENO);
bool canSendStderr; bool canSendStderr;
pid_t myPid;
@ -58,11 +57,7 @@ pid_t myPid;
socket. */ socket. */
static void tunnelStderr(const unsigned char * buf, size_t count) static void tunnelStderr(const unsigned char * buf, size_t count)
{ {
/* Don't send the message to the client if we're a child of the if (canSendStderr) {
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 { try {
writeInt(STDERR_NEXT, to); writeInt(STDERR_NEXT, to);
writeString(buf, count, to); writeString(buf, count, to);
@ -663,7 +658,6 @@ static void performOp(bool trusted, unsigned int clientVersion,
static void processConnection(bool trusted) static void processConnection(bool trusted)
{ {
canSendStderr = false; canSendStderr = false;
myPid = getpid();
_writeToStderr = tunnelStderr; _writeToStderr = tunnelStderr;
#ifdef HAVE_HUP_NOTIFICATION #ifdef HAVE_HUP_NOTIFICATION