Gavin Andresen: multiple instance check, -testnet use port 18333

git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@170 1a98c847-1fd6-4fd8-948a-caf3550aa51b
This commit is contained in:
s_nakamoto
2010-10-20 16:12:23 +00:00
parent 2ea5fa0710
commit d9c6b09ac4
5 changed files with 27 additions and 21 deletions

View File

@@ -244,8 +244,7 @@ bool AppInit2(int argc, char* argv[])
// Required to protect the database files if we're going to keep deleting log.*
//
#if defined(__WXMSW__) && defined(GUI)
// todo: wxSingleInstanceChecker wasn't working on Linux, never deleted its lock file
// maybe should go by whether successfully bind port 8333 instead
// wxSingleInstanceChecker doesn't work on Linux
wxString strMutexName = wxString("bitcoin_running.") + getenv("HOMEPATH");
for (int i = 0; i < strMutexName.size(); i++)
if (!isalnum(strMutexName[i]))
@@ -257,7 +256,6 @@ bool AppInit2(int argc, char* argv[])
unsigned int nStart = GetTime();
loop
{
// TODO: find out how to do this in Linux, or replace with wxWidgets commands
// Show the previous instance and exit
HWND hwndPrev = FindWindowA("wxWindowClassNR", "Bitcoin");
if (hwndPrev)
@@ -281,8 +279,18 @@ bool AppInit2(int argc, char* argv[])
}
#endif
// Make sure only a single bitcoin process is using the data directory.
string strLockFile = GetDataDir() + "/.lock";
FILE* file = fopen(strLockFile.c_str(), "a"); // empty lock file; created if it doesn't exist.
fclose(file);
static boost::interprocess::file_lock lock(strLockFile.c_str());
if (!lock.try_lock())
{
wxMessageBox(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin is probably already running."), GetDataDir().c_str()), "Bitcoin");
return false;
}
// Bind to the port early so we can tell if another instance is already running.
// This is a backup to wxSingleInstanceChecker, which doesn't work on Linux.
string strErrors;
if (!BindListenPort(strErrors))
{