Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoind.cpp
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | static bool AppInit(int argc, char *argv[]) { | ||||
// | // | ||||
// Parameters | // Parameters | ||||
// | // | ||||
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's | // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's | ||||
// main() | // main() | ||||
SetupServerArgs(); | SetupServerArgs(); | ||||
std::string error; | std::string error; | ||||
if (!gArgs.ParseParameters(argc, argv, error)) { | if (!gArgs.ParseParameters(argc, argv, error)) { | ||||
return InitError( | return InitError(Untranslated( | ||||
strprintf("Error parsing command line arguments: %s\n", error)); | strprintf("Error parsing command line arguments: %s\n", error))); | ||||
} | } | ||||
// Process help and version before taking care about datadir | // Process help and version before taking care about datadir | ||||
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { | if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { | ||||
std::string strUsage = | std::string strUsage = | ||||
PACKAGE_NAME " version " + FormatFullVersion() + "\n"; | PACKAGE_NAME " version " + FormatFullVersion() + "\n"; | ||||
if (gArgs.IsArgSet("-version")) { | if (gArgs.IsArgSet("-version")) { | ||||
strUsage += FormatParagraph(LicenseInfo()); | strUsage += FormatParagraph(LicenseInfo()); | ||||
} else { | } else { | ||||
strUsage += "\nUsage: bitcoind [options] " | strUsage += "\nUsage: bitcoind [options] " | ||||
"Start " PACKAGE_NAME "\n"; | "Start " PACKAGE_NAME "\n"; | ||||
strUsage += "\n" + gArgs.GetHelpMessage(); | strUsage += "\n" + gArgs.GetHelpMessage(); | ||||
} | } | ||||
tfm::format(std::cout, "%s", strUsage); | tfm::format(std::cout, "%s", strUsage); | ||||
return true; | return true; | ||||
} | } | ||||
try { | try { | ||||
if (!CheckDataDirOption()) { | if (!CheckDataDirOption()) { | ||||
return InitError( | return InitError(Untranslated( | ||||
strprintf("Specified data directory \"%s\" does not exist.\n", | strprintf("Specified data directory \"%s\" does not exist.\n", | ||||
gArgs.GetArg("-datadir", ""))); | gArgs.GetArg("-datadir", "")))); | ||||
} | } | ||||
if (!gArgs.ReadConfigFiles(error, true)) { | if (!gArgs.ReadConfigFiles(error, true)) { | ||||
return InitError( | return InitError(Untranslated( | ||||
strprintf("Error reading configuration file: %s\n", error)); | strprintf("Error reading configuration file: %s\n", error))); | ||||
} | } | ||||
// Check for -chain, -testnet or -regtest parameter (Params() calls are | // Check for -chain, -testnet or -regtest parameter (Params() calls are | ||||
// only valid after this clause) | // only valid after this clause) | ||||
try { | try { | ||||
SelectParams(gArgs.GetChainName()); | SelectParams(gArgs.GetChainName()); | ||||
node.chain = interfaces::MakeChain(node, config.GetChainParams()); | node.chain = interfaces::MakeChain(node, config.GetChainParams()); | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
return InitError(strprintf("%s\n", e.what())); | return InitError(Untranslated(strprintf("%s\n", e.what()))); | ||||
} | } | ||||
// Make sure we create the net-specific data directory early on: if it | // Make sure we create the net-specific data directory early on: if it | ||||
// is new, this has a side effect of also creating | // is new, this has a side effect of also creating | ||||
// <datadir>/<net>/wallets/. | // <datadir>/<net>/wallets/. | ||||
// | // | ||||
// TODO: this should be removed once GetDataDir() no longer creates the | // TODO: this should be removed once GetDataDir() no longer creates the | ||||
// wallets/ subdirectory. | // wallets/ subdirectory. | ||||
// See more info at: | // See more info at: | ||||
// https://reviews.bitcoinabc.org/D3312 | // https://reviews.bitcoinabc.org/D3312 | ||||
GetDataDir(true); | GetDataDir(true); | ||||
// Error out when loose non-argument tokens are encountered on command | // Error out when loose non-argument tokens are encountered on command | ||||
// line | // line | ||||
for (int i = 1; i < argc; i++) { | for (int i = 1; i < argc; i++) { | ||||
if (!IsSwitchChar(argv[i][0])) { | if (!IsSwitchChar(argv[i][0])) { | ||||
return InitError( | return InitError(Untranslated( | ||||
strprintf("Command line contains unexpected token '%s', " | strprintf("Command line contains unexpected token '%s', " | ||||
"see bitcoind -h for a list of options.\n", | "see bitcoind -h for a list of options.\n", | ||||
argv[i])); | argv[i]))); | ||||
} | } | ||||
} | } | ||||
// -server defaults to true for bitcoind but not for the GUI so do this | // -server defaults to true for bitcoind but not for the GUI so do this | ||||
// here | // here | ||||
gArgs.SoftSetBoolArg("-server", true); | gArgs.SoftSetBoolArg("-server", true); | ||||
// Set this early so that parameter interactions go to console | // Set this early so that parameter interactions go to console | ||||
InitLogging(); | InitLogging(); | ||||
Show All 19 Lines | |||||
#pragma GCC diagnostic push | #pragma GCC diagnostic push | ||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | ||||
#endif | #endif | ||||
tfm::format(std::cout, PACKAGE_NAME " starting\n"); | tfm::format(std::cout, PACKAGE_NAME " starting\n"); | ||||
// Daemonize | // Daemonize | ||||
if (daemon(1, 0)) { | if (daemon(1, 0)) { | ||||
// don't chdir (1), do close FDs (0) | // don't chdir (1), do close FDs (0) | ||||
return InitError( | return InitError(Untranslated( | ||||
strprintf("daemon() failed: %s\n", strerror(errno))); | strprintf("daemon() failed: %s\n", strerror(errno)))); | ||||
} | } | ||||
#if defined(MAC_OSX) | #if defined(MAC_OSX) | ||||
#pragma GCC diagnostic pop | #pragma GCC diagnostic pop | ||||
#endif | #endif | ||||
#else | #else | ||||
return InitError( | return InitError(Untranslated( | ||||
"-daemon is not supported on this operating system\n"); | "-daemon is not supported on this operating system\n")); | ||||
#endif // HAVE_DECL_DAEMON | #endif // HAVE_DECL_DAEMON | ||||
} | } | ||||
// Lock data directory after daemonization | // Lock data directory after daemonization | ||||
if (!AppInitLockDataDirectory()) { | if (!AppInitLockDataDirectory()) { | ||||
// If locking the data directory failed, exit immediately | // If locking the data directory failed, exit immediately | ||||
return false; | return false; | ||||
} | } | ||||
Show All 29 Lines |