aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/db.cpp
diff options
context:
space:
mode:
authorMeshCollider <dobsonsa68@gmail.com>2017-12-26 19:41:55 +1300
committerMeshCollider <dobsonsa68@gmail.com>2018-01-16 19:05:46 +1300
commit2f3bd47d44634cfc0a4261e64af178407ce2869c (patch)
treea604dd3608644a7cc968253bde02cbedbd30d916 /src/wallet/db.cpp
parent5260a4aca1e6c11e1dbca9d3390c0dc739e81204 (diff)
downloadbitcoin-2f3bd47d44634cfc0a4261e64af178407ce2869c.tar.xz
Abstract directory locking into util.cpp
Diffstat (limited to 'src/wallet/db.cpp')
-rw-r--r--src/wallet/db.cpp21
1 files changed, 1 insertions, 20 deletions
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index e3366e1060..23c6279128 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -18,7 +18,6 @@
#include <sys/stat.h>
#endif
-#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/thread.hpp>
namespace {
@@ -53,24 +52,6 @@ void CheckUniqueFileid(const CDBEnv& env, const std::string& filename, Db& db)
}
}
}
-
-bool LockEnvDirectory(const fs::path& env_path)
-{
- // Make sure only a single Bitcoin process is using the wallet directory.
- fs::path lock_file_path = env_path / ".walletlock";
- FILE* file = fsbridge::fopen(lock_file_path, "a"); // empty lock file; created if it doesn't exist.
- if (file) fclose(file);
-
- try {
- static boost::interprocess::file_lock lock(lock_file_path.string().c_str());
- if (!lock.try_lock()) {
- return false;
- }
- } catch (const boost::interprocess::interprocess_exception& e) {
- return error("Error obtaining lock on wallet directory %s: %s.", env_path.string(), e.what());
- }
- return true;
-}
} // namespace
//
@@ -122,7 +103,7 @@ bool CDBEnv::Open(const fs::path& pathIn, bool retry)
boost::this_thread::interruption_point();
strPath = pathIn.string();
- if (!LockEnvDirectory(pathIn)) {
+ if (!LockDirectory(pathIn, ".walletlock")) {
LogPrintf("Cannot obtain a lock on wallet directory %s. Another instance of bitcoin may be using it.\n", strPath);
return false;
}