Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
#include <boost/thread.hpp> | #include <boost/thread.hpp> | ||||
#if ENABLE_ZMQ | #if ENABLE_ZMQ | ||||
#include <zmq/zmqnotificationinterface.h> | #include <zmq/zmqnotificationinterface.h> | ||||
#include <zmq/zmqrpc.h> | #include <zmq/zmqrpc.h> | ||||
#endif | #endif | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
#include <attributes.h> | |||||
#include <cerrno> | |||||
#include <csignal> | #include <csignal> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#endif | #endif | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <memory> | #include <memory> | ||||
static const bool DEFAULT_PROXYRANDOMIZE = true; | static const bool DEFAULT_PROXYRANDOMIZE = true; | ||||
Show All 10 Lines | |||||
#ifdef WIN32 | #ifdef WIN32 | ||||
// Win32 LevelDB doesn't use filedescriptors, and the ones used for accessing | // Win32 LevelDB doesn't use filedescriptors, and the ones used for accessing | ||||
// block files don't count towards the fd_set size limit anyway. | // block files don't count towards the fd_set size limit anyway. | ||||
#define MIN_CORE_FILEDESCRIPTORS 0 | #define MIN_CORE_FILEDESCRIPTORS 0 | ||||
#else | #else | ||||
#define MIN_CORE_FILEDESCRIPTORS 150 | #define MIN_CORE_FILEDESCRIPTORS 150 | ||||
#endif | #endif | ||||
/** | |||||
* 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 | // Shutdown | ||||
// | // | ||||
// | // | ||||
// Thread management and startup/shutdown: | // Thread management and startup/shutdown: | ||||
// | // | ||||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | if (g_zmq_notification_interface) { | ||||
UnregisterValidationInterface(g_zmq_notification_interface); | UnregisterValidationInterface(g_zmq_notification_interface); | ||||
delete g_zmq_notification_interface; | delete g_zmq_notification_interface; | ||||
g_zmq_notification_interface = nullptr; | g_zmq_notification_interface = nullptr; | ||||
} | } | ||||
#endif | #endif | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
try { | try { | ||||
fs::remove(GetPidFile()); | if (!fs::remove(GetPidFile())) { | ||||
LogPrintf("%s: Unable to remove PID file: File does not exist\n", | |||||
__func__); | |||||
} | |||||
} catch (const fs::filesystem_error &e) { | } catch (const fs::filesystem_error &e) { | ||||
LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what()); | LogPrintf("%s: Unable to remove PID file: %s\n", __func__, e.what()); | ||||
} | } | ||||
#endif | #endif | ||||
interfaces.chain_clients.clear(); | interfaces.chain_clients.clear(); | ||||
UnregisterAllValidationInterfaces(); | UnregisterAllValidationInterfaces(); | ||||
GetMainSignals().UnregisterBackgroundSignalScheduler(); | GetMainSignals().UnregisterBackgroundSignalScheduler(); | ||||
GetMainSignals().UnregisterWithMempoolSignals(g_mempool); | GetMainSignals().UnregisterWithMempoolSignals(g_mempool); | ||||
globalVerifyHandle.reset(); | globalVerifyHandle.reset(); | ||||
ECC_Stop(); | ECC_Stop(); | ||||
▲ Show 20 Lines • Show All 1,593 Lines • ▼ Show 20 Lines | |||||
bool AppInitMain(Config &config, RPCServer &rpcServer, | bool AppInitMain(Config &config, RPCServer &rpcServer, | ||||
HTTPRPCRequestProcessor &httpRPCRequestProcessor, | HTTPRPCRequestProcessor &httpRPCRequestProcessor, | ||||
InitInterfaces &interfaces) { | InitInterfaces &interfaces) { | ||||
// Step 4a: application initialization | // Step 4a: application initialization | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
CreatePidFile(GetPidFile(), getpid()); | if (!CreatePidFile()) { | ||||
// Detailed error printed inside CreatePidFile(). | |||||
return false; | |||||
} | |||||
#endif | #endif | ||||
BCLog::Logger &logger = LogInstance(); | BCLog::Logger &logger = LogInstance(); | ||||
if (logger.m_print_to_file) { | if (logger.m_print_to_file) { | ||||
if (gArgs.GetBoolArg("-shrinkdebugfile", | if (gArgs.GetBoolArg("-shrinkdebugfile", | ||||
logger.DefaultShrinkDebugFile())) { | logger.DefaultShrinkDebugFile())) { | ||||
// Do this first since it both loads a bunch of debug.log into | // Do this first since it both loads a bunch of debug.log into | ||||
// memory, and because this needs to happen before any other | // memory, and because this needs to happen before any other | ||||
▲ Show 20 Lines • Show All 665 Lines • Show Last 20 Lines |