aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Weiss <[email protected]>2015-05-18 19:37:43 -0400
committerAdam Weiss <[email protected]>2015-05-22 14:15:22 -0400
commitffdda4e8a7987de85221d3ca3137593a77d8f5f5 (patch)
treeae466ea44b5d80bf2825af8cb9b6cc6173a20194 /src
parentMerge pull request #5159 (diff)
downloaddiscoin-ffdda4e8a7987de85221d3ca3137593a77d8f5f5.tar.xz
discoin-ffdda4e8a7987de85221d3ca3137593a77d8f5f5.zip
Catch errors on datadir lock and pidfile delete
Prevents bad permissions (or other fs related problems) from resulting in hard crashes with cryptic messages on startup and shutdown.
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 47cbda32f..87e989f16 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -187,7 +187,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
@@ -862,9 +866,15 @@ bool AppInit2(boost::thread_group& threadGroup)
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