@@ -1072,19 +1072,22 @@ bool AppInitParameterInteraction(const ArgsManager& args)
10721072 return true ;
10731073}
10741074
1075- static bool LockDataDirectory ( bool probeOnly)
1075+ static bool LockDirectory ( const fs::path& dir, bool probeOnly)
10761076{
1077- // Make sure only a single Bitcoin process is using the data directory.
1078- const fs::path& datadir = gArgs .GetDataDirNet ();
1079- switch (util::LockDirectory (datadir, " .lock" , probeOnly)) {
1077+ // Make sure only a single process is using the directory.
1078+ switch (util::LockDirectory (dir, " .lock" , probeOnly)) {
10801079 case util::LockResult::ErrorWrite:
1081- return InitError (strprintf (_ (" Cannot write to data directory '%s'; check permissions." ), fs::PathToString (datadir )));
1080+ return InitError (strprintf (_ (" Cannot write to directory '%s'; check permissions." ), fs::PathToString (dir )));
10821081 case util::LockResult::ErrorLock:
1083- return InitError (strprintf (_ (" Cannot obtain a lock on data directory %s. %s is probably already running." ), fs::PathToString (datadir ), CLIENT_NAME));
1082+ return InitError (strprintf (_ (" Cannot obtain a lock on directory %s. %s is probably already running." ), fs::PathToString (dir ), CLIENT_NAME));
10841083 case util::LockResult::Success: return true ;
10851084 } // no default case, so the compiler can warn about missing cases
10861085 assert (false );
10871086}
1087+ static bool LockDirectories (bool probeOnly)
1088+ {
1089+ return LockDirectory (gArgs .GetDataDirNet (), probeOnly);
1090+ }
10881091
10891092bool AppInitSanityChecks (const kernel::Context& kernel)
10901093{
@@ -1099,19 +1102,19 @@ bool AppInitSanityChecks(const kernel::Context& kernel)
10991102 return InitError (strprintf (_ (" Elliptic curve cryptography sanity check failure. %s is shutting down." ), CLIENT_NAME));
11001103 }
11011104
1102- // Probe the data directory lock to give an early error message, if possible
1103- // We cannot hold the data directory lock here, as the forking for daemon() hasn't yet happened,
1104- // and a fork will cause weird behavior to it .
1105- return LockDataDirectory (true );
1105+ // Probe the directory locks to give an early error message, if possible
1106+ // We cannot hold the directory locks here, as the forking for daemon() hasn't yet happened,
1107+ // and a fork will cause weird behavior to them .
1108+ return LockDirectories (true );
11061109}
11071110
1108- bool AppInitLockDataDirectory ()
1111+ bool AppInitLockDirectories ()
11091112{
1110- // After daemonization get the data directory lock again and hold on to it until exit
1113+ // After daemonization get the directory locks again and hold on to them until exit
11111114 // This creates a slight window for a race condition to happen, however this condition is harmless: it
11121115 // will at most make us exit without printing a message to console.
1113- if (!LockDataDirectory (false )) {
1114- // Detailed error printed inside LockDataDirectory
1116+ if (!LockDirectories (false )) {
1117+ // Detailed error printed inside LockDirectory
11151118 return false ;
11161119 }
11171120 return true ;
0 commit comments