aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-04-15 12:09:50 -0400
committerGavin Andresen <gavinandresen@gmail.com>2011-04-15 12:09:50 -0400
commitbf3a0902ef98365d803e4a03853dbf0f83511026 (patch)
tree02957d6a4731a99b93232631285b363ad85d1dcb
parent9a189be7401c583fd74fc7f3d7812327323ceecb (diff)
parent66fb32d267d90fe2e1f652570bc45aba26be55fa (diff)
downloadbitcoin-bf3a0902ef98365d803e4a03853dbf0f83511026.tar.xz
Merge branch 'master' of https://github.com/gjs278/bitcoin
-rw-r--r--init.cpp5
-rw-r--r--util.cpp19
-rw-r--r--util.h2
3 files changed, 26 insertions, 0 deletions
diff --git a/init.cpp b/init.cpp
index 906bcbe137..68ed11f6b8 100644
--- a/init.cpp
+++ b/init.cpp
@@ -41,6 +41,7 @@ void Shutdown(void* parg)
DBFlush(false);
StopNode();
DBFlush(true);
+ boost::filesystem::remove(GetPidFile());
CreateThread(ExitTimeout, NULL);
Sleep(50);
printf("Bitcoin exiting\n\n");
@@ -151,6 +152,7 @@ bool AppInit2(int argc, char* argv[])
" bitcoin [options] help <command> \t\t " + _("Get help for a command\n") +
_("Options:\n") +
" -conf=<file> \t\t " + _("Specify configuration file (default: bitcoin.conf)\n") +
+ " -pid=<file> \t\t " + _("Specify pid file (default: bitcoind.pid)\n") +
" -gen \t\t " + _("Generate coins\n") +
" -gen=0 \t\t " + _("Don't generate coins\n") +
" -min \t\t " + _("Start minimized\n") +
@@ -251,7 +253,10 @@ bool AppInit2(int argc, char* argv[])
return false;
}
if (pid > 0)
+ {
+ CreatePidFile(GetPidFile(), pid);
return true;
+ }
pid_t sid = setsid();
if (sid < 0)
diff --git a/util.cpp b/util.cpp
index 1c685ba42d..2359616689 100644
--- a/util.cpp
+++ b/util.cpp
@@ -747,6 +747,25 @@ void ReadConfigFile(map<string, string>& mapSettingsRet,
}
}
+string GetPidFile()
+{
+ namespace fs = boost::filesystem;
+ fs::path pathConfig(GetArg("-pid", "bitcoind.pid"));
+ if (!pathConfig.is_complete())
+ pathConfig = fs::path(GetDataDir()) / pathConfig;
+ return pathConfig.string();
+}
+
+void CreatePidFile(string pidFile, pid_t pid)
+{
+ FILE* file;
+ if (file = fopen(pidFile.c_str(), "w"))
+ {
+ fprintf(file, "%d\n", pid);
+ fclose(file);
+ }
+}
+
int GetFilesize(FILE* file)
{
int nSavePos = ftell(file);
diff --git a/util.h b/util.h
index d1754c9e5e..44afffcbf6 100644
--- a/util.h
+++ b/util.h
@@ -172,6 +172,8 @@ bool WildcardMatch(const string& str, const string& mask);
int GetFilesize(FILE* file);
void GetDataDir(char* pszDirRet);
string GetConfigFile();
+string GetPidFile();
+void CreatePidFile(string pidFile, pid_t pid);
void ReadConfigFile(map<string, string>& mapSettingsRet, map<string, vector<string> >& mapMultiSettingsRet);
#ifdef __WXMSW__
string MyGetSpecialFolderPath(int nFolder, bool fCreate);