about summary refs log tree commit diff
path: root/src/nix-worker/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-worker/main.cc')
-rw-r--r--src/nix-worker/main.cc18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/nix-worker/main.cc b/src/nix-worker/main.cc
index 6a0dcc13d56c..4397697bab2f 100644
--- a/src/nix-worker/main.cc
+++ b/src/nix-worker/main.cc
@@ -10,10 +10,12 @@
 #include <unistd.h>
 #include <signal.h>
 #include <sys/types.h>
+#include <sys/wait.h>
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <fcntl.h>
+#include <errno.h>
 
 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);