From 3782075a5fd4ad0c15a6119e8cdaf136898f679e Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 14 Feb 2019 22:53:03 +0200 Subject: Move all PID file stuff to init.cpp It is only used from init.cpp. Move-only refactoring. --- src/init.cpp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index f8be487cb..63dc671fd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -94,6 +94,30 @@ std::unique_ptr g_banman; static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat"; +/** + * The PID file facilities. + */ +#ifndef WIN32 +static const char* BITCOIN_PID_FILENAME = "bitcoind.pid"; + +static fs::path GetPidFile() +{ + return AbsPathForConfigVal(fs::path(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME))); +} + +NODISCARD static bool CreatePidFile() +{ + FILE* file = fsbridge::fopen(GetPidFile(), "w"); + if (file) { + fprintf(file, "%d\n", getpid()); + fclose(file); + return true; + } else { + return InitError(strprintf(_("Unable to create the PID file '%s': %s"), GetPidFile().string(), std::strerror(errno))); + } +} +#endif + ////////////////////////////////////////////////////////////////////////////// // // Shutdown @@ -1194,20 +1218,6 @@ bool AppInitLockDataDirectory() return true; } -#ifndef WIN32 -NODISCARD static bool CreatePidFile() -{ - FILE* file = fsbridge::fopen(GetPidFile(), "w"); - if (file) { - fprintf(file, "%d\n", getpid()); - fclose(file); - return true; - } else { - return InitError(strprintf(_("Unable to create the PID file '%s': %s"), GetPidFile().string(), std::strerror(errno))); - } -} -#endif - bool AppInitMain(InitInterfaces& interfaces) { const CChainParams& chainparams = Params(); -- cgit v1.2.3