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"
13 #include <boost/algorithm/string/predicate.hpp>
14 #include <boost/filesystem.hpp>
15 #include <boost/thread.hpp>
17 /* Introduction text for doxygen: */
19 /*! \mainpage Developer documentation
21 * \section intro_sec Introduction
23 * This is the developer documentation of the reference client for an experimental new digital currency called Bitcoin (https://www.bitcoin.org/),
24 * which enables instant payments to anyone, anywhere in the world. Bitcoin uses peer-to-peer technology to operate
25 * with no central authority: managing transactions and issuing money are carried out collectively by the network.
27 * The software is a community-driven open source project, released under the MIT license.
30 * Use the buttons <code>Namespaces</code>, <code>Classes</code> or <code>Files</code> at the top of the page to start navigating the code.
35 void WaitForShutdown(boost::thread_group
* threadGroup
)
37 bool fShutdown
= ShutdownRequested();
38 // Tell the main threads to shutdown.
42 fShutdown
= ShutdownRequested();
46 threadGroup
->interrupt_all();
47 threadGroup
->join_all();
51 //////////////////////////////////////////////////////////////////////////////
55 bool AppInit(int argc
, char* argv
[])
57 boost::thread_group threadGroup
;
64 // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
65 ParseParameters(argc
, argv
);
67 // Process help and version before taking care about datadir
68 if (mapArgs
.count("-?") || mapArgs
.count("-help") || mapArgs
.count("-version"))
70 std::string strUsage
= _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";
72 if (mapArgs
.count("-version"))
74 strUsage
+= LicenseInfo();
78 strUsage
+= "\n" + _("Usage:") + "\n" +
79 " bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n";
81 strUsage
+= "\n" + HelpMessage(HMM_BITCOIND
);
84 fprintf(stdout
, "%s", strUsage
.c_str());
90 if (!boost::filesystem::is_directory(GetDataDir(false)))
92 fprintf(stderr
, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs
["-datadir"].c_str());
97 ReadConfigFile(mapArgs
, mapMultiArgs
);
98 } catch (const std::exception
& e
) {
99 fprintf(stderr
,"Error reading configuration file: %s\n", e
.what());
102 // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
103 if (!SelectParamsFromCommandLine()) {
104 fprintf(stderr
, "Error: Invalid combination of -regtest and -testnet.\n");
109 bool fCommandLine
= false;
110 for (int i
= 1; i
< argc
; i
++)
111 if (!IsSwitchChar(argv
[i
][0]) && !boost::algorithm::istarts_with(argv
[i
], "bitcoin:"))
116 fprintf(stderr
, "Error: There is no RPC client functionality in bitcoind anymore. Use the bitcoin-cli utility instead.\n");
120 fDaemon
= GetBoolArg("-daemon", false);
123 fprintf(stdout
, "Bitcoin server starting\n");
129 fprintf(stderr
, "Error: fork() returned %d errno %d\n", pid
, errno
);
132 if (pid
> 0) // Parent process, pid is child process id
136 // Child process falls through to rest of initialization
138 pid_t sid
= setsid();
140 fprintf(stderr
, "Error: setsid() returned %d errno %d\n", sid
, errno
);
143 SoftSetBoolArg("-server", true);
145 fRet
= AppInit2(threadGroup
);
147 catch (const std::exception
& e
) {
148 PrintExceptionContinue(&e
, "AppInit()");
150 PrintExceptionContinue(NULL
, "AppInit()");
155 threadGroup
.interrupt_all();
156 // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
157 // the startup-failure cases to make sure they don't result in a hang due to some
158 // thread-blocking-waiting-for-another-thread-during-startup case
160 WaitForShutdown(&threadGroup
);
167 int main(int argc
, char* argv
[])
171 // Connect bitcoind signal handlers
174 return (AppInit(argc
, argv
) ? 0 : 1);