@@ -1072,19 +1072,22 @@ bool AppInitParameterInteraction(const ArgsManager& args)
1072
1072
return true ;
1073
1073
}
1074
1074
1075
- static bool LockDataDirectory ( bool probeOnly)
1075
+ static bool LockDirectory ( const fs::path& dir, bool probeOnly)
1076
1076
{
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)) {
1080
1079
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 )));
1082
1081
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));
1084
1083
case util::LockResult::Success: return true ;
1085
1084
} // no default case, so the compiler can warn about missing cases
1086
1085
assert (false );
1087
1086
}
1087
+ static bool LockDirectories (bool probeOnly)
1088
+ {
1089
+ return LockDirectory (gArgs .GetDataDirNet (), probeOnly);
1090
+ }
1088
1091
1089
1092
bool AppInitSanityChecks (const kernel::Context& kernel)
1090
1093
{
@@ -1099,19 +1102,19 @@ bool AppInitSanityChecks(const kernel::Context& kernel)
1099
1102
return InitError (strprintf (_ (" Elliptic curve cryptography sanity check failure. %s is shutting down." ), CLIENT_NAME));
1100
1103
}
1101
1104
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 );
1106
1109
}
1107
1110
1108
- bool AppInitLockDataDirectory ()
1111
+ bool AppInitLockDirectories ()
1109
1112
{
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
1111
1114
// This creates a slight window for a race condition to happen, however this condition is harmless: it
1112
1115
// 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
1115
1118
return false ;
1116
1119
}
1117
1120
return true ;
0 commit comments