6#if defined(HAVE_CONFIG_H)
7#include <config/bitcoin-config.h>
54int fork_daemon(
bool nochdir,
bool noclose,
TokenPipeEnd &endpoint) {
69 endpoint = umbilical->TakeReadEnd();
70 umbilical->TakeWriteEnd().
Close();
82 endpoint = umbilical->TakeWriteEnd();
83 umbilical->TakeReadEnd().
Close();
93 if (chdir(
"/") != 0) {
101 int fd = open(
"/dev/null", O_RDWR);
103 bool err = dup2(fd, STDIN_FILENO) < 0 ||
104 dup2(fd, STDOUT_FILENO) < 0 ||
105 dup2(fd, STDERR_FILENO) < 0;
139 std::any context{&
node};
154 strprintf(
"Error parsing command line arguments: %s", error)));
159 std::string strUsage =
165 strUsage +=
"\nUsage: bitcoind [options] "
166 "Start " PACKAGE_NAME
"\n";
186 return InitError(err->message, err->details);
200 for (
int i = 1; i < argc; i++) {
203 strprintf(
"Command line contains unexpected token '%s', "
204 "see bitcoind -h for a list of options.",
226 node.kernel = std::make_unique<kernel::Context>();
236 tfm::format(std::cout, PACKAGE_NAME
" starting\n");
240 switch (fork_daemon(1, 0, daemon_ep)) {
262 tfm::format(std::cerr,
"Error during initialization - "
263 "check debug.log for details\n");
270 "-daemon is not supported on this operating system"));
281 }
catch (
const std::exception &e) {
297 node.exit_status = EXIT_FAILURE;
305int main(
int argc,
char *argv[]) {
307 common::WinCmdLineArgs winArgs;
308 std::tie(argc, argv) = winArgs.get();
317 return (
AppInit(
node, argc, argv) ?
node.exit_status.load() : EXIT_FAILURE);
bool HelpRequested(const ArgsManager &args)
bool IsSwitchChar(char c)
int main(int argc, char *argv[])
static bool AppInit(NodeContext &node, int argc, char *argv[])
const std::function< std::string(const char *)> G_TRANSLATION_FUN
Translate string to current locale using Qt.
#define Assert(val)
Identity function.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
std::string GetHelpMessage() const
Get the help string.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Class for registering and managing all RPC calls.
bool IsOpen()
Return whether endpoint is open.
int TokenWrite(uint8_t token)
Write token to endpoint.
void Close()
Explicit close function.
int TokenRead()
Read token from endpoint.
static std::optional< TokenPipe > Make()
Create a new pipe.
std::string FormatFullVersion()
std::string LicenseInfo()
Returns licensing information (for -version)
const Config & GetConfig()
void PrintExceptionContinue(const std::exception *pex, std::string_view thread_name)
void Interrupt(NodeContext &node)
Interrupt threads.
void InitLogging(const ArgsManager &args)
Initialize global loggers.
bool AppInitLockDataDirectory()
Lock bitcoin data directory.
void SetupServerArgs(NodeContext &node)
Register all arguments with the ArgsManager.
void Shutdown(NodeContext &node)
bool AppInitBasicSetup(const ArgsManager &args, std::atomic< int > &exit_status)
Initialize bitcoin: Basic context setup.
bool AppInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor, NodeContext &node, interfaces::BlockAndHeaderTipInfo *tip_info)
Bitcoin main initialization.
bool AppInitInterfaces(NodeContext &node)
Initialize node and wallet interface pointers.
void InitParameterInteraction(ArgsManager &args)
Parameter interaction: change current parameters depending on various rules.
bool AppInitParameterInteraction(Config &config, const ArgsManager &args)
Initialization: parameter interaction.
bool AppInitSanityChecks(const kernel::Context &kernel)
Initialization sanity checks.
static constexpr bool DEFAULT_DAEMON
Default value for -daemon option.
static constexpr bool DEFAULT_DAEMONWAIT
Default value for -daemonwait option.
std::optional< ConfigError > InitConfig(ArgsManager &args, SettingsAbortFn settings_abort_fn)
Read config files, and create datadir and settings.json if they don't exist.
void ThreadSetInternalName(std::string &&)
Set the internal (in-memory) name of the current thread only.
void noui_connect()
Connect all bitcoind signal handlers.
void WaitForShutdown()
Wait for StartShutdown to be called in any thread.
NodeContext struct containing references to chain state and connection state.
std::string SysErrorString(int err)
Return system error string from errno value.
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
bool InitError(const bilingual_str &str)
Show error message.
std::string FormatParagraph(std::string_view in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.