diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2007-05-01 15:16:17 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2007-05-01 15:16:17 +0000 |
commit | cbfac2fdccc83b04d9c2027e9e21070d4ac7c7e5 (patch) | |
tree | 9bff2f93fb123a3ad05bb3712e3d2a875c6da53b /src/libutil | |
parent | 644946feed146396c00c288337bad26428970aa4 (diff) | |
download | guix-cbfac2fdccc83b04d9c2027e9e21070d4ac7c7e5.tar.gz |
* Set a terminate() handler to ensure that we leave the BDB
environment cleanly even when an exception is thrown from a destructor. We still crash, but we don't take all other Nix processes with us.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 20 | ||||
-rw-r--r-- | src/libutil/util.hh | 5 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index ae5af24920..d61b35bdfb 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -444,7 +444,11 @@ void warnOnce(bool & haveWarned, const format & f) static void defaultWriteToStderr(const unsigned char * buf, size_t count) { - writeFull(STDERR_FILENO, buf, count); + try { + writeFull(STDERR_FILENO, buf, count); + } catch (SysError & e) { + /* ignore EPIPE etc. */ + } } @@ -545,8 +549,8 @@ AutoCloseFD::~AutoCloseFD() { try { close(); - } catch (Error & e) { - printMsg(lvlError, format("error (ignored): %1%") % e.msg()); + } catch (...) { + ignoreException(); } } @@ -968,5 +972,15 @@ bool string2Int(const string & s, int & n) return str && str.get() == EOF; } + +void ignoreException() +{ + try { + throw; + } catch (std::exception & e) { + printMsg(lvlError, format("error (ignored): %1%") % e.what()); + } +} + } diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 4d284ccfdc..63389867fe 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -280,6 +280,11 @@ string int2String(int n); bool string2Int(const string & s, int & n); +/* Exception handling in destructors: print an error message, then + ignore the exception. */ +void ignoreException(); + + } |