Skip to content

Commit 3782075

Browse files
committed
Move all PID file stuff to init.cpp
It is only used from init.cpp. Move-only refactoring.
1 parent 561e375 commit 3782075

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

src/init.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,30 @@ std::unique_ptr<BanMan> g_banman;
9494

9595
static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat";
9696

97+
/**
98+
* The PID file facilities.
99+
*/
100+
#ifndef WIN32
101+
static const char* BITCOIN_PID_FILENAME = "bitcoind.pid";
102+
103+
static fs::path GetPidFile()
104+
{
105+
return AbsPathForConfigVal(fs::path(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME)));
106+
}
107+
108+
NODISCARD static bool CreatePidFile()
109+
{
110+
FILE* file = fsbridge::fopen(GetPidFile(), "w");
111+
if (file) {
112+
fprintf(file, "%d\n", getpid());
113+
fclose(file);
114+
return true;
115+
} else {
116+
return InitError(strprintf(_("Unable to create the PID file '%s': %s"), GetPidFile().string(), std::strerror(errno)));
117+
}
118+
}
119+
#endif
120+
97121
//////////////////////////////////////////////////////////////////////////////
98122
//
99123
// Shutdown
@@ -1194,20 +1218,6 @@ bool AppInitLockDataDirectory()
11941218
return true;
11951219
}
11961220

1197-
#ifndef WIN32
1198-
NODISCARD static bool CreatePidFile()
1199-
{
1200-
FILE* file = fsbridge::fopen(GetPidFile(), "w");
1201-
if (file) {
1202-
fprintf(file, "%d\n", getpid());
1203-
fclose(file);
1204-
return true;
1205-
} else {
1206-
return InitError(strprintf(_("Unable to create the PID file '%s': %s"), GetPidFile().string(), std::strerror(errno)));
1207-
}
1208-
}
1209-
#endif
1210-
12111221
bool AppInitMain(InitInterfaces& interfaces)
12121222
{
12131223
const CChainParams& chainparams = Params();

src/util/system.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
const int64_t nStartupTime = GetTime();
8080

8181
const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf";
82-
const char * const BITCOIN_PID_FILENAME = "bitcoind.pid";
8382

8483
ArgsManager gArgs;
8584

@@ -958,13 +957,6 @@ std::string ArgsManager::GetChainName() const
958957
return CBaseChainParams::MAIN;
959958
}
960959

961-
#ifndef WIN32
962-
fs::path GetPidFile()
963-
{
964-
return AbsPathForConfigVal(fs::path(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME)));
965-
}
966-
#endif
967-
968960
bool RenameOver(fs::path src, fs::path dest)
969961
{
970962
#ifdef WIN32

src/util/system.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
int64_t GetStartupTime();
4040

4141
extern const char * const BITCOIN_CONF_FILENAME;
42-
extern const char * const BITCOIN_PID_FILENAME;
4342

4443
/** Translate a message to the native language of the user. */
4544
const extern std::function<std::string(const char*)> G_TRANSLATION_FUN;
@@ -84,9 +83,6 @@ const fs::path &GetBlocksDir();
8483
const fs::path &GetDataDir(bool fNetSpecific = true);
8584
void ClearDatadirCache();
8685
fs::path GetConfigFile(const std::string& confPath);
87-
#ifndef WIN32
88-
fs::path GetPidFile();
89-
#endif
9086
#ifdef WIN32
9187
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
9288
#endif

0 commit comments

Comments
 (0)