diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-12-12 14:35:44 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-12-12 14:35:44 +0100 |
commit | 28f22b4653bfcf1be41b042c8068b6513dd3e931 (patch) | |
tree | 9eadec69bd2e6b35c204976e752bccd48bb07df8 /src/libutil | |
parent | 5a2d45164899479cb3dfe94cb7659fd522163acc (diff) |
Ensure we're writing to stderr in the builder
http://hydra.nixos.org/build/17862041
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 25 | ||||
-rw-r--r-- | src/libutil/util.hh | 1 |
2 files changed, 14 insertions, 12 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index a91cf26aa..1f71f76d5 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -265,7 +265,7 @@ void writeFile(const Path & path, const string & s) AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0666); if (fd == -1) throw SysError(format("opening file ‘%1%’") % path); - writeFull(fd, (unsigned char *) s.data(), s.size()); + writeFull(fd, s); } @@ -292,7 +292,7 @@ string readLine(int fd) void writeLine(int fd, string s) { s += '\n'; - writeFull(fd, (const unsigned char *) s.data(), s.size()); + writeFull(fd, s); } @@ -483,18 +483,13 @@ 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 { - auto p = _writeToStderr; - if (!p) p = defaultWriteToStderr; - p((const unsigned char *) s.data(), s.size()); + if (_writeToStderr) + _writeToStderr((const unsigned char *) s.data(), s.size()); + else + writeFull(STDERR_FILENO, s); } catch (SysError & e) { /* Ignore failing writes to stderr if we're in an exception handler, otherwise throw an exception. We need to ignore @@ -506,7 +501,7 @@ void writeToStderr(const string & s) } -void (*_writeToStderr) (const unsigned char * buf, size_t count) = defaultWriteToStderr; +void (*_writeToStderr) (const unsigned char * buf, size_t count) = 0; void readFull(int fd, unsigned char * buf, size_t count) @@ -540,6 +535,12 @@ void writeFull(int fd, const unsigned char * buf, size_t count) } +void writeFull(int fd, const string & s) +{ + writeFull(fd, (const unsigned char *) s.data(), s.size()); +} + + string drainFD(int fd) { string result; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 09eb4d6e2..352b83e70 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -171,6 +171,7 @@ extern void (*_writeToStderr) (const unsigned char * buf, size_t count); requested number of bytes. */ void readFull(int fd, unsigned char * buf, size_t count); void writeFull(int fd, const unsigned char * buf, size_t count); +void writeFull(int fd, const string & s); MakeError(EndOfFile, Error) |