| 695 | } |
| 696 | |
| 697 | static 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 |
no test coverage detected