1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #include "clientversion.h"
11 #include "ui_interface.h"
14 #include <boost/algorithm/string/predicate.hpp>
15 #include <boost/filesystem.hpp>
16 #include <boost/thread.hpp>
18 /* Introduction text for doxygen: */
20 /*! \mainpage Developer documentation
22 * \section intro_sec Introduction
24 * This is the developer documentation of the reference client for an experimental new digital currency called Bitcoin (https://www.bitcoin.org/),
25 * which enables instant payments to anyone, anywhere in the world. Bitcoin uses peer-to-peer technology to operate
26 * with no central authority: managing transactions and issuing money are carried out collectively by the network.
28 * The software is a community-driven open source project, released under the MIT license.
31 * Use the buttons <code>Namespaces</code>, <code>Classes</code> or <code>Files</code> at the top of the page to start navigating the code.
36 void WaitForShutdown(boost::thread_group* threadGroup)
38 bool fShutdown = ShutdownRequested();
39 // Tell the main threads to shutdown.
43 fShutdown = ShutdownRequested();
47 threadGroup->interrupt_all();
48 threadGroup->join_all();
52 //////////////////////////////////////////////////////////////////////////////
56 bool AppInit(int argc, char* argv[])
58 boost::thread_group threadGroup;
65 // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
66 ParseParameters(argc, argv);
68 // Process help and version before taking care about datadir
69 if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
71 std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";
73 if (mapArgs.count("-version"))
75 strUsage += LicenseInfo();
79 strUsage += "\n" + _("Usage:") + "\n" +
80 " bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n";
82 strUsage += "\n" + HelpMessage(HMM_BITCOIND);
85 fprintf(stdout, "%s", strUsage.c_str());
91 if (!boost::filesystem::is_directory(GetDataDir(false)))
93 fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
98 ReadConfigFile(mapArgs, mapMultiArgs);
99 } catch (const std::exception& e) {
100 fprintf(stderr,"Error reading configuration file: %s\n", e.what());
103 // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
104 if (!SelectParamsFromCommandLine()) {
105 fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
110 bool fCommandLine = false;
111 for (int i = 1; i < argc; i++)
112 if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "bitcoin:"))
117 fprintf(stderr, "Error: There is no RPC client functionality in bitcoind anymore. Use the bitcoin-cli utility instead.\n");
121 fDaemon = GetBoolArg("-daemon", false);
124 fprintf(stdout, "Bitcoin server starting\n");
130 fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
133 if (pid > 0) // Parent process, pid is child process id
137 // Child process falls through to rest of initialization
139 pid_t sid = setsid();
141 fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
144 SoftSetBoolArg("-server", true);
146 fRet = AppInit2(threadGroup);
148 catch (const std::exception& e) {
149 PrintExceptionContinue(&e, "AppInit()");
151 PrintExceptionContinue(NULL, "AppInit()");
156 threadGroup.interrupt_all();
157 // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
158 // the startup-failure cases to make sure they don't result in a hang due to some
159 // thread-blocking-waiting-for-another-thread-during-startup case
161 WaitForShutdown(&threadGroup);
168 int main(int argc, char* argv[])
172 // Connect bitcoind signal handlers
175 return (AppInit(argc, argv) ? 0 : 1);