about summary refs log tree commit diff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-10-04T11·44+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-10-04T11·44+0000
commit71dfe4b90bec29075f01cfbc45f8f521535bf460 (patch)
tree401ac9b86c11b969f97dd4e3b4557b626c638e39 /src/libutil/util.cc
parente4907411c2d902215d1a18456ce8b0c653650461 (diff)
parent450837bcc887a47260817611d01c22e35aba92b6 (diff)
* Sync with the trunk.
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 2d26fc66dafe..e7c0700cf41d 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -481,7 +481,16 @@ void printMsg_(Verbosity level, const format & f)
     else if (logType == ltEscapes && level != lvlInfo)
         prefix = "\033[" + escVerbosity(level) + "s";
     string s = (format("%1%%2%\n") % prefix % f.str()).str();
-    writeToStderr((const unsigned char *) s.c_str(), s.size());
+    try {
+        writeToStderr((const unsigned char *) s.c_str(), 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
+           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;
+    }
 }