aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-05-24 10:54:02 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2015-05-24 10:57:22 +0200
commite1412d3e96ff11d05d727bebedcc42698853cccc (patch)
tree938af47079ce4e2162d86a9aef8e592b3e9c4bc4 /src
parent2d84241d2680e88d4ca2333436d7b3a86a784408 (diff)
parentffdda4e8a7987de85221d3ca3137593a77d8f5f5 (diff)
Merge pull request #6159
ffdda4e Catch errors on datadir lock and pidfile delete (Adam Weiss)
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 490ed6f54c..b44233d90f 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -188,7 +188,11 @@ void Shutdown()
pwalletMain->Flush(true);
#endif
#ifndef WIN32
- boost::filesystem::remove(GetPidFile());
+ try {
+ boost::filesystem::remove(GetPidFile());
+ } catch (const boost::filesystem::filesystem_error& e) {
+ LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what());
+ }
#endif
UnregisterAllValidationInterfaces();
#ifdef ENABLE_WALLET
@@ -863,9 +867,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
if (file) fclose(file);
- static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
- if (!lock.try_lock())
- return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running."), strDataDir));
+
+ try {
+ static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
+ if (!lock.try_lock())
+ 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
CreatePidFile(GetPidFile(), getpid());
#endif