summary refs log tree commit diff
path: root/nix/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-01 19:29:03 +0200
committerLudovic Courtès <ludo@gnu.org>2015-05-11 17:15:44 +0200
commitb732ffd28ddf50d3150e4f276a0e8488e38eaacb (patch)
tree67f1ad8764ed0758cad3a39d45b15cd567c8e6bd /nix/libutil
parentc51374c128cbe1f06acd95ba2d627a118a95aabf (diff)
downloadguix-b732ffd28ddf50d3150e4f276a0e8488e38eaacb.tar.gz
Call commonChildInit() before doing chroot init
This ensures that daemon clients see error messages from the chroot
setup.
Diffstat (limited to 'nix/libutil')
-rw-r--r--nix/libutil/util.cc18
1 files changed, 10 insertions, 8 deletions
diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc
index 06c8441aed..b79212018b 100644
--- a/nix/libutil/util.cc
+++ b/nix/libutil/util.cc
@@ -466,10 +466,18 @@ void warnOnce(bool & haveWarned, const FormatOrString & fs)
 }
 
 
+static void defaultWriteToStderr(const unsigned char * buf, size_t count)
+{
+    writeFull(STDERR_FILENO, buf, count);
+}
+
+
 void writeToStderr(const string & s)
 {
     try {
-        _writeToStderr((const unsigned char *) s.data(), s.size());
+        auto p = _writeToStderr;
+        if (!p) p = defaultWriteToStderr;
+        p((const unsigned char *) s.data(), s.size());
     } catch (SysError & e) {
         /* Ignore failing writes to stderr if we're in an exception
            handler, otherwise throw an exception.  We need to ignore
@@ -481,12 +489,6 @@ void writeToStderr(const string & s)
 }
 
 
-static void defaultWriteToStderr(const unsigned char * buf, size_t count)
-{
-    writeFull(STDERR_FILENO, buf, count);
-}
-
-
 void (*_writeToStderr) (const unsigned char * buf, size_t count) = defaultWriteToStderr;
 
 
@@ -849,7 +851,7 @@ pid_t startProcess(std::function<void()> fun, const string & errorPrefix)
     if (pid == -1) throw SysError("unable to fork");
 
     if (pid == 0) {
-        _writeToStderr = defaultWriteToStderr;
+        _writeToStderr = 0;
         try {
             restoreAffinity();
             fun();