summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--nix/libutil/util.cc8
-rw-r--r--nix/libutil/util.hh3
-rw-r--r--nix/nix-daemon/nix-daemon.cc4
3 files changed, 10 insertions, 5 deletions
diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc
index ad3b3c387f..a4a1ddb12a 100644
--- a/nix/libutil/util.cc
+++ b/nix/libutil/util.cc
@@ -858,7 +858,8 @@ void killUser(uid_t uid)
 //////////////////////////////////////////////////////////////////////
 
 
-pid_t startProcess(std::function<void()> fun, const string & errorPrefix)
+pid_t startProcess(std::function<void()> fun,
+    bool dieWithParent, const string & errorPrefix, bool runExitHandlers)
 {
     pid_t pid = fork();
     if (pid == -1) throw SysError("unable to fork");
@@ -873,7 +874,10 @@ pid_t startProcess(std::function<void()> fun, const string & errorPrefix)
                 std::cerr << errorPrefix << e.what() << "\n";
             } catch (...) { }
         } catch (...) { }
-        _exit(1);
+        if (runExitHandlers)
+            exit(1);
+        else
+            _exit(1);
     }
 
     return pid;
diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh
index 418d76daec..0ad0026711 100644
--- a/nix/libutil/util.hh
+++ b/nix/libutil/util.hh
@@ -269,7 +269,8 @@ void killUser(uid_t uid);
 
 /* Fork a process that runs the given function, and return the child
    pid to the caller. */
-pid_t startProcess(std::function<void()> fun, const string & errorPrefix = "error: ");
+pid_t startProcess(std::function<void()> fun, bool dieWithParent = true,
+    const string & errorPrefix = "error: ", bool runExitHandlers = false);
 
 
 /* Run a program and return its stdout in a string (i.e., like the
diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc
index 2fa3632dfe..e42d602a3a 100644
--- a/nix/nix-daemon/nix-daemon.cc
+++ b/nix/nix-daemon/nix-daemon.cc
@@ -924,8 +924,8 @@ static void daemonLoop()
                 to.fd = remote;
                 processConnection(trusted);
 
-                _exit(0);
-            }, "unexpected Nix daemon error: ");
+                exit(0);
+            }, false, "unexpected Nix daemon error: ", true);
 
         } catch (Interrupted & e) {
             throw;