diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-08-01T17·29+0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-08-01T17·29+0200 |
commit | 4c4b219c07c08c709c94af6f3fe1f25dea0563a0 (patch) | |
tree | c0ef03604dfd6a807bea25a8431a3064174e4bb3 /src/libutil | |
parent | eea0401d7a8ed1292f71d697e7a59c429aa18d5d (diff) |
Call commonChildInit() before doing chroot init
This ensures that daemon clients see error messages from the chroot setup.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 18 |
1 files changed, 10 insertions, 8 deletions
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(); |