diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -135,27 +135,18 @@ } } + // Make sure we setup and lock data dir after daemonization + ParameterSetup(); + if (!AppInitBase(config, rpcServer)) { + // InitError will have been called with detailed error, which ends + // up on console + exit(EXIT_FAILURE); + } + // -server defaults to true for bitcoind but not for the GUI so do this // here gArgs.SoftSetBoolArg("-server", true); // Set this early so that parameter interactions go to console - InitLogging(); - InitParameterInteraction(); - if (!AppInitBasicSetup()) { - // InitError will have been called with detailed error, which ends - // up on console - exit(1); - } - if (!AppInitParameterInteraction(config, rpcServer)) { - // InitError will have been called with detailed error, which ends - // up on console - exit(1); - } - if (!AppInitSanityChecks()) { - // InitError will have been called with detailed error, which ends - // up on console - exit(1); - } if (gArgs.GetBoolArg("-daemon", false)) { #if HAVE_DECL_DAEMON fprintf(stdout, "Bitcoin server starting\n"); @@ -177,7 +168,6 @@ // Lock data directory after daemonization if (!AppInitLockDataDirectory()) { - // If locking the data directory failed, exit immediately exit(EXIT_FAILURE); } fRet = AppInitMain(config, httpRPCRequestProcessor, threadGroup, diff --git a/src/init.h b/src/init.h --- a/src/init.h +++ b/src/init.h @@ -60,6 +60,18 @@ * AppInitSanityChecks should have been called. */ bool AppInitLockDataDirectory(); + +/** + * Setup logging and parameter interactions + */ +void ParameterSetup(); + +/** + * Init Base: Basic Setup init parameter interaction, sanity checks, and lock + * the data dir. + */ +bool AppInitBase(Config &config, RPCServer &rpcServer); + /** * Bitcoin main initialization. * @note This should only be done after daemonization. diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -1252,6 +1252,11 @@ return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind); } +void ParameterSetup() { + InitLogging(); + InitParameterInteraction(); +} + void InitLogging() { BCLog::Logger &logger = GetLogger(); logger.m_print_to_console = gArgs.GetBoolArg("-printtoconsole", false); @@ -1745,6 +1750,22 @@ return true; } +bool AppInitBase(Config &config, RPCServer &rpcServer) { + if (!AppInitBasicSetup()) { + return false; + } + if (!AppInitParameterInteraction(config, rpcServer)) { + return false; + } + if (!AppInitSanityChecks()) { + return false; + } + if (!AppInitLockDataDirectory()) { + return false; + } + return true; +} + bool AppInitMain(Config &config, HTTPRPCRequestProcessor &httpRPCRequestProcessor, boost::thread_group &threadGroup, CScheduler &scheduler) { diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -169,12 +169,6 @@ public: explicit BitcoinABC(); - /** - * Basic initialization, before starting initialization/shutdown thread. - * Return true on success. - */ - static bool baseInitialize(Config &config, RPCServer &rpcServer); - public Q_SLOTS: void initialize(Config *config, HTTPRPCRequestProcessor *httpRPCRequestProcessor); @@ -204,8 +198,6 @@ /// Create payment server void createPaymentServer(); #endif - /// parameter interaction/setup based on rules - void parameterSetup(); /// Create options model void createOptionsModel(bool resetSettings); /// Create main window @@ -267,22 +259,6 @@ Q_EMIT runawayException(QString::fromStdString(GetWarnings("gui"))); } -bool BitcoinABC::baseInitialize(Config &config, RPCServer &rpcServer) { - if (!AppInitBasicSetup()) { - return false; - } - if (!AppInitParameterInteraction(config, rpcServer)) { - return false; - } - if (!AppInitSanityChecks()) { - return false; - } - if (!AppInitLockDataDirectory()) { - return false; - } - return true; -} - void BitcoinABC::initialize(Config *cfg, HTTPRPCRequestProcessor *httpRPCRequestProcessor) { Config &config(*cfg); @@ -423,11 +399,6 @@ coreThread->start(); } -void BitcoinApplication::parameterSetup() { - InitLogging(); - InitParameterInteraction(); -} - void BitcoinApplication::requestInitialize( Config &config, HTTPRPCRequestProcessor &httpRPCRequestProcessor, RPCServer &rpcServer) { @@ -751,7 +722,7 @@ // Install qDebug() message handler to route to debug.log qInstallMessageHandler(DebugMessageHandler); // Allow parameter interaction before we create the options model - app.parameterSetup(); + ParameterSetup(); // Load GUI settings from QSettings app.createOptionsModel(gArgs.IsArgSet("-resetguisettings")); @@ -775,7 +746,7 @@ // initialization/shutdown thread. This is acceptable because this // function only contains steps that are quick to execute, so the GUI // thread won't be held up. - if (BitcoinABC::baseInitialize(config, rpcServer)) { + if (AppInitBase(config, rpcServer)) { app.requestInitialize(config, httpRPCRequestProcessor, rpcServer); #if defined(Q_OS_WIN) WinShutdownMonitor::registerShutdownBlockReason(