Merge pull request #6159

ffdda4e Catch errors on datadir lock and pidfile delete (Adam Weiss)
This commit is contained in:
Wladimir J. van der Laan 2015-05-24 10:54:02 +02:00
commit e1412d3e96
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6

View File

@ -188,7 +188,11 @@ void Shutdown()
pwalletMain->Flush(true); pwalletMain->Flush(true);
#endif #endif
#ifndef WIN32 #ifndef WIN32
try {
boost::filesystem::remove(GetPidFile()); boost::filesystem::remove(GetPidFile());
} catch (const boost::filesystem::filesystem_error& e) {
LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what());
}
#endif #endif
UnregisterAllValidationInterfaces(); UnregisterAllValidationInterfaces();
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
@ -863,9 +867,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
boost::filesystem::path pathLockFile = GetDataDir() / ".lock"; boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist. FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
if (file) fclose(file); if (file) fclose(file);
try {
static boost::interprocess::file_lock lock(pathLockFile.string().c_str()); static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
if (!lock.try_lock()) if (!lock.try_lock())
return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running."), strDataDir)); return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running."), strDataDir));
} catch(const boost::interprocess::interprocess_exception& e) {
return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running.") + " %s.", strDataDir, e.what()));
}
#ifndef WIN32 #ifndef WIN32
CreatePidFile(GetPidFile(), getpid()); CreatePidFile(GetPidFile(), getpid());
#endif #endif