Merge pull request #4951

d6712db Also create pid file in non-daemon mode (Wladimir J. van der Laan)
This commit is contained in:
Wladimir J. van der Laan 2014-09-22 10:32:01 +02:00
commit aa340a8f07
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
4 changed files with 9 additions and 4 deletions

View File

@ -129,7 +129,6 @@ bool AppInit(int argc, char* argv[])
} }
if (pid > 0) // Parent process, pid is child process id if (pid > 0) // Parent process, pid is child process id
{ {
CreatePidFile(GetPidFile(), pid);
return true; return true;
} }
// Child process falls through to rest of initialization // Child process falls through to rest of initialization

View File

@ -160,7 +160,9 @@ void Shutdown()
if (pwalletMain) if (pwalletMain)
bitdb.Flush(true); bitdb.Flush(true);
#endif #endif
#ifndef WIN32
boost::filesystem::remove(GetPidFile()); boost::filesystem::remove(GetPidFile());
#endif
UnregisterAllWallets(); UnregisterAllWallets();
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
if (pwalletMain) if (pwalletMain)
@ -228,7 +230,9 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += " -maxorphanblocks=<n> " + strprintf(_("Keep at most <n> unconnectable blocks in memory (default: %u)"), DEFAULT_MAX_ORPHAN_BLOCKS) + "\n"; strUsage += " -maxorphanblocks=<n> " + strprintf(_("Keep at most <n> unconnectable blocks in memory (default: %u)"), DEFAULT_MAX_ORPHAN_BLOCKS) + "\n";
strUsage += " -maxorphantx=<n> " + strprintf(_("Keep at most <n> unconnectable transactions in memory (default: %u)"), DEFAULT_MAX_ORPHAN_TRANSACTIONS) + "\n"; strUsage += " -maxorphantx=<n> " + strprintf(_("Keep at most <n> unconnectable transactions in memory (default: %u)"), DEFAULT_MAX_ORPHAN_TRANSACTIONS) + "\n";
strUsage += " -par=<n> " + strprintf(_("Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)"), -(int)boost::thread::hardware_concurrency(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS) + "\n"; strUsage += " -par=<n> " + strprintf(_("Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)"), -(int)boost::thread::hardware_concurrency(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS) + "\n";
#ifndef WIN32
strUsage += " -pid=<file> " + _("Specify pid file (default: bitcoind.pid)") + "\n"; strUsage += " -pid=<file> " + _("Specify pid file (default: bitcoind.pid)") + "\n";
#endif
strUsage += " -reindex " + _("Rebuild block chain index from current blk000??.dat files") + " " + _("on startup") + "\n"; strUsage += " -reindex " + _("Rebuild block chain index from current blk000??.dat files") + " " + _("on startup") + "\n";
#if !defined(WIN32) #if !defined(WIN32)
strUsage += " -sysperms " + _("Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)") + "\n"; strUsage += " -sysperms " + _("Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)") + "\n";
@ -714,7 +718,9 @@ bool AppInit2(boost::thread_group& threadGroup)
static boost::interprocess::file_lock lock(pathLockFile.string().c_str()); static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
if (!lock.try_lock()) if (!lock.try_lock())
return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running."), strDataDir)); return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running."), strDataDir));
#ifndef WIN32
CreatePidFile(GetPidFile(), getpid());
#endif
if (GetBoolArg("-shrinkdebugfile", !fDebug)) if (GetBoolArg("-shrinkdebugfile", !fDebug))
ShrinkDebugFile(); ShrinkDebugFile();
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

View File

@ -472,6 +472,7 @@ void ReadConfigFile(map<string, string>& mapSettingsRet,
ClearDatadirCache(); ClearDatadirCache();
} }
#ifndef WIN32
boost::filesystem::path GetPidFile() boost::filesystem::path GetPidFile()
{ {
boost::filesystem::path pathPidFile(GetArg("-pid", "bitcoind.pid")); boost::filesystem::path pathPidFile(GetArg("-pid", "bitcoind.pid"));
@ -479,7 +480,6 @@ boost::filesystem::path GetPidFile()
return pathPidFile; return pathPidFile;
} }
#ifndef WIN32
void CreatePidFile(const boost::filesystem::path &path, pid_t pid) void CreatePidFile(const boost::filesystem::path &path, pid_t pid)
{ {
FILE* file = fopen(path.string().c_str(), "w"); FILE* file = fopen(path.string().c_str(), "w");

View File

@ -93,8 +93,8 @@ bool TryCreateDirectory(const boost::filesystem::path& p);
boost::filesystem::path GetDefaultDataDir(); boost::filesystem::path GetDefaultDataDir();
const boost::filesystem::path &GetDataDir(bool fNetSpecific = true); const boost::filesystem::path &GetDataDir(bool fNetSpecific = true);
boost::filesystem::path GetConfigFile(); boost::filesystem::path GetConfigFile();
boost::filesystem::path GetPidFile();
#ifndef WIN32 #ifndef WIN32
boost::filesystem::path GetPidFile();
void CreatePidFile(const boost::filesystem::path &path, pid_t pid); void CreatePidFile(const boost::filesystem::path &path, pid_t pid);
#endif #endif
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet); void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);