about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libutil/logging.cc12
-rw-r--r--src/libutil/util.cc16
-rw-r--r--src/libutil/util.hh4
3 files changed, 15 insertions, 17 deletions
diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc
index 15bb1e175da6..0229ba472998 100644
--- a/src/libutil/logging.cc
+++ b/src/libutil/logging.cc
@@ -60,14 +60,12 @@ void warnOnce(bool & haveWarned, const FormatOrString & fs)
 void writeToStderr(const string & s)
 {
     try {
-        writeFull(STDERR_FILENO, s);
+        writeFull(STDERR_FILENO, s, false);
     } catch (SysError & e) {
-        /* Ignore failing writes to stderr if we're in an exception
-           handler, otherwise throw an exception.  We need to ignore
-           write errors in exception handlers to ensure that cleanup
-           code runs to completion if the other side of stderr has
-           been closed unexpectedly. */
-        if (!std::uncaught_exception()) throw;
+        /* Ignore failing writes to stderr.  We need to ignore write
+           errors to ensure that cleanup code that logs to stderr runs
+           to completion if the other side of stderr has been closed
+           unexpectedly. */
     }
 }
 
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 87e97c20fa3d..8e029fb4874a 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -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) {
-        checkInterrupt();
         ssize_t res = write(fd, (char *) buf, count);
-        if (res == -1) {
-            if (errno == EINTR) continue;
+        if (res == -1 && errno != EINTR)
             throw SysError("writing to file");
+        if (res > 0) {
+            count -= res;
+            buf += res;
         }
-        count -= res;
-        buf += res;
+        if (allowInterrupts) checkInterrupt();
     }
 }
 
 
-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);
 }
 
 
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 7aeca0edc026..9bf54832699e 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -120,8 +120,8 @@ void replaceSymlink(const Path & target, const Path & link);
 /* Wrappers arount read()/write() that read/write exactly the
    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);
+void writeFull(int fd, const unsigned char * buf, size_t count, bool allowInterrupts = true);
+void writeFull(int fd, const string & s, bool allowInterrupts = true);
 
 MakeError(EndOfFile, Error)