diff options
-rw-r--r-- | src/libstore/build.cc | 10 | ||||
-rw-r--r-- | src/libutil/util.cc | 18 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 479bc4a243a2..03aea8b8e88d 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -374,8 +374,6 @@ void Goal::trace(const format & f) /* Common initialisation performed in child processes. */ static void commonChildInit(Pipe & logPipe) { - restoreAffinity(); - /* Put the child in a separate session (and thus a separate process group) so that it has no controlling terminal (meaning that e.g. ssh cannot open /dev/tty) and it doesn't receive @@ -1962,6 +1960,12 @@ void DerivationGoal::initChild() try { /* child */ + _writeToStderr = 0; + + restoreAffinity(); + + commonChildInit(builderOut); + #if CHROOT_ENABLED if (useChroot) { /* Initialise the loopback interface. */ @@ -2080,8 +2084,6 @@ void DerivationGoal::initChild() } #endif - commonChildInit(builderOut); - if (chdir(tmpDir.c_str()) == -1) throw SysError(format("changing into `%1%'") % tmpDir); diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 595e7243ec1a..44087d58e513 100644 --- a/src/libutil/util.cc +++ b/src/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(); |