diff options
Diffstat (limited to 'src/bitcoind.cpp')
| -rw-r--r-- | src/bitcoind.cpp | 107 |
1 files changed, 52 insertions, 55 deletions
diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 5d8721884..cce687ac9 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -1,18 +1,19 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying +// Copyright (c) 2009-2013 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "clientversion.h" #include "rpcserver.h" -#include "rpcclient.h" #include "init.h" #include "main.h" #include "noui.h" -#include "ui_interface.h" +#include "scheduler.h" #include "util.h" #include <boost/algorithm/string/predicate.hpp> #include <boost/filesystem.hpp> +#include <boost/thread.hpp> /* Introduction text for doxygen: */ @@ -20,7 +21,7 @@ * * \section intro_sec Introduction * - * This is the developer documentation of the reference client for an experimental new digital currency called Bitcoin (http://www.bitcoin.org/), + * This is the developer documentation of the reference client for an experimental new digital currency called Bitcoin (https://www.bitcoin.org/), * which enables instant payments to anyone, anywhere in the world. Bitcoin uses peer-to-peer technology to operate * with no central authority: managing transactions and issuing money are carried out collectively by the network. * @@ -32,7 +33,7 @@ static bool fDaemon; -void DetectShutdownThread(boost::thread_group* threadGroup) +void WaitForShutdown(boost::thread_group* threadGroup) { bool fShutdown = ShutdownRequested(); // Tell the main threads to shutdown. @@ -55,43 +56,54 @@ void DetectShutdownThread(boost::thread_group* threadGroup) bool AppInit(int argc, char* argv[]) { boost::thread_group threadGroup; - boost::thread* detectShutdownThread = NULL; + CScheduler scheduler; bool fRet = false; + + // + // Parameters + // + // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main() + ParseParameters(argc, argv); + + // Process help and version before taking care about datadir + if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version")) + { + std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n"; + + if (mapArgs.count("-version")) + { + strUsage += LicenseInfo(); + } + else + { + strUsage += "\n" + _("Usage:") + "\n" + + " bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n"; + + strUsage += "\n" + HelpMessage(HMM_BITCOIND); + } + + fprintf(stdout, "%s", strUsage.c_str()); + return false; + } + try { - // - // Parameters - // - // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main() - ParseParameters(argc, argv); if (!boost::filesystem::is_directory(GetDataDir(false))) { fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str()); return false; } - ReadConfigFile(mapArgs, mapMultiArgs); - // Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause) - if (!SelectParamsFromCommandLine()) { - fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n"); + try + { + ReadConfigFile(mapArgs, mapMultiArgs); + } catch (const std::exception& e) { + fprintf(stderr,"Error reading configuration file: %s\n", e.what()); return false; } - - if (mapArgs.count("-?") || mapArgs.count("--help")) - { - // First part of help message is specific to bitcoind / RPC client - std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n\n" + - _("Usage:") + "\n" + - " bitcoind [options] " + _("Start Bitcoin server") + "\n" + - _("Usage (deprecated, use bitcoin-cli):") + "\n" + - " bitcoind [options] <command> [params] " + _("Send command to Bitcoin server") + "\n" + - " bitcoind [options] help " + _("List commands") + "\n" + - " bitcoind [options] help <command> " + _("Get help for a command") + "\n"; - - strUsage += "\n" + HelpMessage(HMM_BITCOIND); - strUsage += "\n" + HelpMessageCli(false); - - fprintf(stdout, "%s", strUsage.c_str()); + // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) + if (!SelectParamsFromCommandLine()) { + fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n"); return false; } @@ -103,8 +115,8 @@ bool AppInit(int argc, char* argv[]) if (fCommandLine) { - int ret = CommandLineRPC(argc, argv); - exit(ret); + fprintf(stderr, "Error: There is no RPC client functionality in bitcoind anymore. Use the bitcoin-cli utility instead.\n"); + exit(1); } #ifndef WIN32 fDaemon = GetBoolArg("-daemon", false); @@ -121,7 +133,6 @@ bool AppInit(int argc, char* argv[]) } if (pid > 0) // Parent process, pid is child process id { - CreatePidFile(GetPidFile(), pid); return true; } // Child process falls through to rest of initialization @@ -133,10 +144,9 @@ bool AppInit(int argc, char* argv[]) #endif SoftSetBoolArg("-server", true); - detectShutdownThread = new boost::thread(boost::bind(&DetectShutdownThread, &threadGroup)); - fRet = AppInit2(threadGroup); + fRet = AppInit2(threadGroup, scheduler); } - catch (std::exception& e) { + catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { PrintExceptionContinue(NULL, "AppInit()"); @@ -144,20 +154,12 @@ bool AppInit(int argc, char* argv[]) if (!fRet) { - if (detectShutdownThread) - detectShutdownThread->interrupt(); - threadGroup.interrupt_all(); // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of // the startup-failure cases to make sure they don't result in a hang due to some // thread-blocking-waiting-for-another-thread-during-startup case - } - - if (detectShutdownThread) - { - detectShutdownThread->join(); - delete detectShutdownThread; - detectShutdownThread = NULL; + } else { + WaitForShutdown(&threadGroup); } Shutdown(); @@ -166,15 +168,10 @@ bool AppInit(int argc, char* argv[]) int main(int argc, char* argv[]) { - bool fRet = false; + SetupEnvironment(); // Connect bitcoind signal handlers noui_connect(); - fRet = AppInit(argc, argv); - - if (fRet && fDaemon) - return 0; - - return (fRet ? 0 : 1); + return (AppInit(argc, argv) ? 0 : 1); } |