Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | |||||
static const char *BITCOIN_PID_FILENAME = "bitcoind.pid"; | static const char *BITCOIN_PID_FILENAME = "bitcoind.pid"; | ||||
static fs::path GetPidFile() { | static fs::path GetPidFile() { | ||||
return AbsPathForConfigVal( | return AbsPathForConfigVal( | ||||
fs::path(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME))); | fs::path(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME))); | ||||
} | } | ||||
NODISCARD static bool CreatePidFile() { | NODISCARD static bool CreatePidFile() { | ||||
FILE *file = fsbridge::fopen(GetPidFile(), "w"); | fsbridge::ofstream file{GetPidFile()}; | ||||
if (file) { | if (file) { | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
fprintf(file, "%d\n", GetCurrentProcessId()); | tfm::format(file, "%d\n", GetCurrentProcessId()); | ||||
#else | #else | ||||
fprintf(file, "%d\n", getpid()); | tfm::format(file, "%d\n", getpid()); | ||||
#endif | #endif | ||||
fclose(file); | |||||
return true; | return true; | ||||
} else { | } else { | ||||
return InitError(strprintf(_("Unable to create the PID file '%s': %s"), | return InitError(strprintf(_("Unable to create the PID file '%s': %s"), | ||||
GetPidFile().string(), | GetPidFile().string(), | ||||
std::strerror(errno))); | std::strerror(errno))); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,476 Lines • Show Last 20 Lines |