MCPcopy Create free account
hub / github.com/LUX-Core/lux / LockDataDirectory

Function LockDataDirectory

src/init.cpp:697–714  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

695}
696
697static bool LockDataDirectory(bool probeOnly)
698{
699 std::string strDataDir = GetDataDir().string();
700
701 // Make sure only a single Bitcoin process is using the data directory.
702 boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
703 FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
704 if (file) fclose(file);
705
706 try {
707 static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
708 if (!lock.try_lock())
709 return InitError(strprintf(_("Cannot obtain a lock on data directory %s. %s is probably already running."), strDataDir, _(PACKAGE_NAME)));
710 } catch(const boost::interprocess::interprocess_exception& e) {
711 return InitError(strprintf(_("Cannot obtain a lock on data directory %s. %s is probably already running.") + " %s.", strDataDir, _(PACKAGE_NAME), e.what()));
712 }
713 return true;
714}
715
716/** Sanity checks
717 * Ensure that LUX is running in a usable environment with all

Callers 1

UnlockDataDirectoryFunction · 0.85

Calls 3

InitErrorFunction · 0.85
_Function · 0.85
whatMethod · 0.45

Tested by

no test coverage detected