about summary refs log tree commit diff
path: root/src/nix-worker
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2007-03-28T15·46+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2007-03-28T15·46+0000
commit17b506c0c7a927da1befc62100c5354e4b3147f6 (patch)
treef65e0908cc2146a9ddf12dc88490ff38fd7f3600 /src/nix-worker
parentefd31139dfd07600c909fa14870c82d90c6ca9de (diff)
* Handle ECONNRESET from the client. Also, don't abort() if there are
  unexpected conditions in the SIGPOLL handler, since that messes up
  the Berkeley DB environment (which a client must never be able to
  trigger).

Diffstat (limited to 'src/nix-worker')
-rw-r--r--src/nix-worker/nix-worker.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc
index b91e4867c581..078362e9c37b 100644
--- a/src/nix-worker/nix-worker.cc
+++ b/src/nix-worker/nix-worker.cc
@@ -79,8 +79,11 @@ static bool isFarSideClosed(int socket)
        socket as readable because there is actual input or because
        we've reached EOF (i.e., a read of size 0 is available). */
     char c;
-    if (read(socket, &c, 1) != 0)
+    int rd;
+    if ((rd = read(socket, &c, 1)) > 0)
         throw Error("EOF expected (protocol error?)");
+    else if (rd == -1 && errno != ECONNRESET)
+        throw SysError("expected connection reset or EOF");
     
     return true;
 }
@@ -109,7 +112,8 @@ static void sigPollHandler(int sigNo)
                 _isInterrupted = 1;
                 blockInt = 1;
                 canSendStderr = false;
-                write(STDERR_FILENO, "SIGPOLL\n", 8);
+                string s = "SIGPOLL\n";
+                write(STDERR_FILENO, s.c_str(), s.size());
             }
         } else {
             string s = "spurious SIGPOLL\n";
@@ -118,8 +122,9 @@ static void sigPollHandler(int sigNo)
     }
     catch (Error & e) {
         /* Shouldn't happen. */
-        write(STDERR_FILENO, e.msg().c_str(), e.msg().size());
-        abort();
+        string s = "impossible: " + e.msg() + '\n';
+        write(STDERR_FILENO, s.c_str(), s.size());
+        throw;
     }
 }