Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 1,698 Lines • ▼ Show 20 Lines | #endif | ||||
nLocalServices = ServiceFlags(nLocalServices | NODE_BITCOIN_CASH); | nLocalServices = ServiceFlags(nLocalServices | NODE_BITCOIN_CASH); | ||||
nMaxTipAge = gArgs.GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE); | nMaxTipAge = gArgs.GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE); | ||||
return true; | return true; | ||||
} | } | ||||
static bool LockDataDirectory(bool probeOnly) { | static bool LockDataDirectory(bool probeOnly) { | ||||
std::string strDataDir = GetDataDir().string(); | |||||
// Make sure only a single Bitcoin process is using the data directory. | // Make sure only a single Bitcoin process is using the data directory. | ||||
fs::path pathLockFile = GetDataDir() / ".lock"; | fs::path datadir = GetDataDir(); | ||||
// empty lock file; created if it doesn't exist. | if (!LockDirectory(datadir, ".lock", probeOnly)) { | ||||
FILE *file = fsbridge::fopen(pathLockFile, "a"); | |||||
if (file) { | |||||
fclose(file); | |||||
} | |||||
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. %s is " | |||||
"probably already running."), | |||||
strDataDir, _(PACKAGE_NAME))); | |||||
} | |||||
if (probeOnly) { | |||||
lock.unlock(); | |||||
} | |||||
} catch (const boost::interprocess::interprocess_exception &e) { | |||||
return InitError(strprintf(_("Cannot obtain a lock on data directory " | return InitError(strprintf(_("Cannot obtain a lock on data directory " | ||||
"%s. %s is probably already running.") + | "%s. %s is probably already running."), | ||||
" %s.", | datadir.string(), _(PACKAGE_NAME))); | ||||
strDataDir, _(PACKAGE_NAME), e.what())); | |||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool AppInitSanityChecks() { | bool AppInitSanityChecks() { | ||||
// Step 4: sanity checks | // Step 4: sanity checks | ||||
// Initialize elliptic curve code | // Initialize elliptic curve code | ||||
▲ Show 20 Lines • Show All 658 Lines • Show Last 20 Lines |