diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-10-04T11·23+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-10-04T11·23+0000 |
commit | 450837bcc887a47260817611d01c22e35aba92b6 (patch) | |
tree | af0f81ed0572373b84a0642e87f4b702d124a250 | |
parent | 4aa92450832e87018513a2453e39858fab00833a (diff) |
* In printMsg(), 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.
-rw-r--r-- | src/libutil/util.cc | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index c79ce1041c36..32c8fce9a1b1 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -482,7 +482,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; + } } |