printMsg(): Don't check for interrupts

Having the logger function potentially throw exceptions is
Heisenbuggy.
This commit is contained in:
Eelco Dolstra 2016-09-16 18:52:42 +02:00
parent 2e1493037b
commit 054be50257
3 changed files with 15 additions and 17 deletions

View file

@ -60,14 +60,12 @@ void warnOnce(bool & haveWarned, const FormatOrString & fs)
void writeToStderr(const string & s) void writeToStderr(const string & s)
{ {
try { try {
writeFull(STDERR_FILENO, s); writeFull(STDERR_FILENO, s, false);
} catch (SysError & e) { } catch (SysError & e) {
/* Ignore failing writes to stderr if we're in an exception /* Ignore failing writes to stderr. We need to ignore write
handler, otherwise throw an exception. We need to ignore errors to ensure that cleanup code that logs to stderr runs
write errors in exception handlers to ensure that cleanup to completion if the other side of stderr has been closed
code runs to completion if the other side of stderr has unexpectedly. */
been closed unexpectedly. */
if (!std::uncaught_exception()) throw;
} }
} }

View file

@ -474,24 +474,24 @@ 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 unsigned char * buf, size_t count, bool allowInterrupts)
{ {
while (count) { while (count) {
checkInterrupt();
ssize_t res = write(fd, (char *) buf, count); ssize_t res = write(fd, (char *) buf, count);
if (res == -1) { if (res == -1 && errno != EINTR)
if (errno == EINTR) continue;
throw SysError("writing to file"); throw SysError("writing to file");
if (res > 0) {
count -= res;
buf += res;
} }
count -= res; if (allowInterrupts) checkInterrupt();
buf += res;
} }
} }
void writeFull(int fd, const string & s) void writeFull(int fd, const string & s, bool allowInterrupts)
{ {
writeFull(fd, (const unsigned char *) s.data(), s.size()); writeFull(fd, (const unsigned char *) s.data(), s.size(), allowInterrupts);
} }

View file

@ -120,8 +120,8 @@ void replaceSymlink(const Path & target, const Path & link);
/* Wrappers arount read()/write() that read/write exactly the /* Wrappers arount read()/write() that read/write exactly the
requested number of bytes. */ requested number of bytes. */
void readFull(int fd, unsigned char * buf, size_t count); 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 unsigned char * buf, size_t count, bool allowInterrupts = true);
void writeFull(int fd, const string & s); void writeFull(int fd, const string & s, bool allowInterrupts = true);
MakeError(EndOfFile, Error) MakeError(EndOfFile, Error)