Merged R8632

This commit is contained in:
Wouter den Breejen 2007-10-08 10:15:18 +00:00
parent 3800f55b54
commit 8e9c7d9338
6 changed files with 53 additions and 8 deletions

View File

@ -7,6 +7,7 @@
#include <iostream>
#include <cctype>
#include <exception>
#include <sys/stat.h>
#include <unistd.h>
@ -81,6 +82,23 @@ struct RemoveTempRoots
void initDerivationsHelpers();
static void closeStore()
{
try {
throw;
} catch (std::exception & e) {
printMsg(lvlError,
format("FATAL: unexpected exception (closing store and aborting): %1%") % e.what());
}
try {
store.reset((StoreAPI *) 0);
} catch (...) {
ignoreException();
}
abort();
}
/* Initialize and reorder arguments, then call the actual argument
processor. */
static void initAndRun(int argc, char * * argv)
@ -206,6 +224,12 @@ static void initAndRun(int argc, char * * argv)
exit. */
RemoveTempRoots removeTempRoots; /* unused variable - don't remove */
/* Make sure that the database gets closed properly, even if
terminate() is called (which happens sometimes due to bugs in
destructor/exceptions interaction, but that needn't preclude a
clean shutdown of the database). */
std::set_terminate(closeStore);
run(remaining);
/* Close the Nix database. */

View File

@ -697,8 +697,8 @@ DerivationGoal::~DerivationGoal()
try {
killChild();
deleteTmpDir(false);
} catch (Error & e) {
printMsg(lvlError, format("error (ignored): %1%") % e.msg());
} catch (...) {
ignoreException();
}
}

View File

@ -274,7 +274,11 @@ LocalStore::LocalStore(bool reserveSpace)
LocalStore::~LocalStore()
{
/* If the database isn't open, this is a NOP. */
nixDB.close();
try {
nixDB.close();
} catch (...) {
ignoreException();
}
}

View File

@ -149,8 +149,8 @@ RemoteStore::~RemoteStore()
fdSocket.close();
if (child != -1)
child.wait(true);
} catch (Error & e) {
printMsg(lvlError, format("error (ignored): %1%") % e.msg());
} catch (...) {
ignoreException();
}
}

View File

@ -446,7 +446,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. */
}
}
@ -548,8 +552,8 @@ AutoCloseFD::~AutoCloseFD()
{
try {
close();
} catch (Error & e) {
printMsg(lvlError, format("error (ignored): %1%") % e.msg());
} catch (...) {
ignoreException();
}
}
@ -1046,6 +1050,15 @@ string unsignedInt2String(unsigned int n)
return str.str();
}
void ignoreException()
{
try {
throw;
} catch (std::exception & e) {
printMsg(lvlError, format("error (ignored): %1%") % e.what());
}
}
bool string2UnsignedInt(const string & s, unsigned int & n)
{
std::istringstream str(s);

View File

@ -336,6 +336,10 @@ void removeSymlink(const string & path);
void ensureStateDir(const Path & statePath, const string & user, const string & group, const string & chmod);
/* Exception handling in destructors: print an error message, then
ignore the exception. */
void ignoreException();
}
#endif /* !__UTIL_H */