wallet: Improve logging when BerkeleyDB environment fails to close

This commit is contained in:
Tim Ruffing 2018-05-09 00:20:12 +02:00
parent 264c643809
commit b6f0b4d859
No known key found for this signature in database
GPG key ID: EACFF772B38B3479

View file

@ -102,7 +102,7 @@ void BerkeleyEnvironment::Close()
int ret = dbenv->close(0); int ret = dbenv->close(0);
if (ret != 0) if (ret != 0)
LogPrintf("BerkeleyEnvironment::EnvShutdown: Error %d shutting down database environment: %s\n", ret, DbEnv::strerror(ret)); LogPrintf("BerkeleyEnvironment::Close: Error %d closing database environment: %s\n", ret, DbEnv::strerror(ret));
if (!fMockDb) if (!fMockDb)
DbEnv((u_int32_t)0).remove(strPath.c_str(), 0); DbEnv((u_int32_t)0).remove(strPath.c_str(), 0);
} }
@ -168,9 +168,12 @@ bool BerkeleyEnvironment::Open(bool retry)
nEnvFlags, nEnvFlags,
S_IRUSR | S_IWUSR); S_IRUSR | S_IWUSR);
if (ret != 0) { if (ret != 0) {
dbenv->close(0);
Reset();
LogPrintf("BerkeleyEnvironment::Open: Error %d opening database environment: %s\n", ret, DbEnv::strerror(ret)); LogPrintf("BerkeleyEnvironment::Open: Error %d opening database environment: %s\n", ret, DbEnv::strerror(ret));
int ret2 = dbenv->close(0);
if (ret2 != 0) {
LogPrintf("BerkeleyEnvironment::Open: Error %d closing failed database environment: %s\n", ret2, DbEnv::strerror(ret2));
}
Reset();
if (retry) { if (retry) {
// try moving the database env out of the way // try moving the database env out of the way
fs::path pathDatabaseBak = pathIn / strprintf("database.%d.bak", GetTime()); fs::path pathDatabaseBak = pathIn / strprintf("database.%d.bak", GetTime());