mirror of
https://github.com/NixOS/nix
synced 2025-06-27 08:31:16 +02:00
* 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.
This commit is contained in:
parent
644946feed
commit
cbfac2fdcc
6 changed files with 55 additions and 8 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue