diff --git a/src/nix-worker/main.cc b/src/nix-worker/main.cc index 6a0dcc13d..4397697ba 100644 --- a/src/nix-worker/main.cc +++ b/src/nix-worker/main.cc @@ -10,10 +10,12 @@ #include #include #include +#include #include #include #include #include +#include using namespace nix; @@ -403,10 +405,17 @@ static void processConnection() } -static void setSigChldAction(bool ignore) +static void sigChldHandler(int sigNo) +{ + /* Reap all dead children. */ + while (waitpid(-1, 0, WNOHANG) == 0) ; +} + + +static void setSigChldAction(bool autoReap) { struct sigaction act, oact; - act.sa_handler = ignore ? SIG_IGN : SIG_DFL; + act.sa_handler = autoReap ? sigChldHandler : SIG_DFL; sigfillset(&act.sa_mask); act.sa_flags = 0; if (sigaction(SIGCHLD, &act, &oact)) @@ -463,7 +472,10 @@ static void daemonLoop() (struct sockaddr *) &remoteAddr, &remoteAddrLen); checkInterrupt(); if (remote == -1) - throw SysError("accepting connection"); + if (errno == EINTR) + continue; + else + throw SysError("accepting connection"); printMsg(lvlInfo, format("accepted connection %1%") % remote);