diff options
author | MeshCollider <dobsonsa68@gmail.com> | 2017-12-26 19:41:55 +1300 |
---|---|---|
committer | MeshCollider <dobsonsa68@gmail.com> | 2018-01-16 19:05:46 +1300 |
commit | 2f3bd47d44634cfc0a4261e64af178407ce2869c (patch) | |
tree | a604dd3608644a7cc968253bde02cbedbd30d916 /src/init.cpp | |
parent | 5260a4aca1e6c11e1dbca9d3390c0dc739e81204 (diff) |
Abstract directory locking into util.cpp
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/src/init.cpp b/src/init.cpp index 7215e87359..b48802637b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1143,23 +1143,10 @@ bool AppInitParameterInteraction() static bool LockDataDirectory(bool probeOnly) { - std::string strDataDir = GetDataDir().string(); - // Make sure only a single Bitcoin process is using the data directory. - fs::path pathLockFile = GetDataDir() / ".lock"; - FILE* file = fsbridge::fopen(pathLockFile, "a"); // empty lock file; created if it doesn't exist. - 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 %s. %s is probably already running.") + " %s.", strDataDir, _(PACKAGE_NAME), e.what())); + fs::path datadir = GetDataDir(); + if (!LockDirectory(datadir, ".lock", probeOnly)) { + return InitError(strprintf(_("Cannot obtain a lock on data directory %s. %s is probably already running."), datadir.string(), _(PACKAGE_NAME))); } return true; } |