Skip to content

Commit 73b6b4e

Browse files
committed
init: Keep track of whether data directory locked, don't cleanup if not
Keep a flag indicating whether the data directory was locked. If not, Interrupt and Shutdown are no-ops. This avoids things from being cleaned up if they were created by another instance.
1 parent 7666250 commit 73b6b4e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/init.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
7575
std::unique_ptr<CConnman> g_connman;
7676
std::unique_ptr<PeerLogicValidation> peerLogic;
7777

78+
/** Set at startup if the data directory was succesfully locked */
79+
bool g_locked_data_directory = false;
80+
7881
#if ENABLE_ZMQ
7982
static CZMQNotificationInterface* pzmqNotificationInterface = NULL;
8083
#endif
@@ -158,6 +161,11 @@ static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
158161

159162
void Interrupt(boost::thread_group& threadGroup)
160163
{
164+
if (!g_locked_data_directory) {
165+
// If we never succeeded in locking the data directory, do not interrupt anything.
166+
// Nothing will have been started anyway.
167+
return;
168+
}
161169
InterruptHTTPServer();
162170
InterruptHTTPRPC();
163171
InterruptRPC();
@@ -170,6 +178,11 @@ void Interrupt(boost::thread_group& threadGroup)
170178

171179
void Shutdown()
172180
{
181+
if (!g_locked_data_directory) {
182+
// If we never succeeded in locking the data directory, do not clean up anything.
183+
// This avoids deleting RPC cookies of the running instance and worse.
184+
return;
185+
}
173186
LogPrintf("%s: In progress...\n", __func__);
174187
static CCriticalSection cs_Shutdown;
175188
TRY_LOCK(cs_Shutdown, lockShutdown);
@@ -1184,6 +1197,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
11841197
// Detailed error printed inside LockDataDirectory
11851198
return false;
11861199
}
1200+
g_locked_data_directory = true;
11871201

11881202
#ifndef WIN32
11891203
CreatePidFile(GetPidFile(), getpid());

0 commit comments

Comments
 (0)