Skip to content

Commit e1412d3

Browse files
committed
Merge pull request #6159
ffdda4e Catch errors on datadir lock and pidfile delete (Adam Weiss)
2 parents 2d84241 + ffdda4e commit e1412d3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/init.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ void Shutdown()
188188
pwalletMain->Flush(true);
189189
#endif
190190
#ifndef WIN32
191-
boost::filesystem::remove(GetPidFile());
191+
try {
192+
boost::filesystem::remove(GetPidFile());
193+
} catch (const boost::filesystem::filesystem_error& e) {
194+
LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what());
195+
}
192196
#endif
193197
UnregisterAllValidationInterfaces();
194198
#ifdef ENABLE_WALLET
@@ -863,9 +867,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
863867
boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
864868
FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
865869
if (file) fclose(file);
866-
static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
867-
if (!lock.try_lock())
868-
return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running."), strDataDir));
870+
871+
try {
872+
static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
873+
if (!lock.try_lock())
874+
return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running."), strDataDir));
875+
} catch(const boost::interprocess::interprocess_exception& e) {
876+
return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running.") + " %s.", strDataDir, e.what()));
877+
}
878+
869879
#ifndef WIN32
870880
CreatePidFile(GetPidFile(), getpid());
871881
#endif

0 commit comments

Comments
 (0)