6 #include <bitcoin-build-config.h> 51 int fork_daemon(
bool nochdir,
bool noclose,
TokenPipeEnd& endpoint)
65 endpoint = umbilical->TakeReadEnd();
66 umbilical->TakeWriteEnd().
Close();
77 endpoint = umbilical->TakeWriteEnd();
78 umbilical->TakeReadEnd().
Close();
87 if (chdir(
"/") != 0) {
94 int fd = open(
"/dev/null", O_RDWR);
96 bool err = dup2(fd, STDIN_FILENO) < 0 || dup2(fd, STDOUT_FILENO) < 0 || dup2(fd, STDERR_FILENO) < 0;
98 if (fd > 2) close(fd);
123 return InitError(error->message, error->details);
127 for (
int i = 1; i < argc; i++) {
139 std::string strUsage = CLIENT_NAME
" daemon version " +
FormatFullVersion() +
"\n";
145 "The " CLIENT_NAME
" daemon (bitcoind) is a headless program that connects to the Bitcoin network to validate and relay transactions and blocks, as well as relaying addresses.\n\n" 146 "It provides the backbone of the Bitcoin network and its RPC, REST and ZMQ services can provide various transaction, block and address-related services.\n\n" 147 "There is an optional wallet component which provides transaction services.\n\n" 148 "It can be used in a headless environment or as part of a server setup.\n" 150 "Usage: bitcoind [options]\n" 175 std::any context{&
node};
192 node.warnings = std::make_unique<node::Warnings>();
194 node.kernel = std::make_unique<kernel::Context>();
195 node.ecc_context = std::make_unique<ECC_Context>();
207 switch (fork_daemon(1, 0, daemon_ep)) {
222 tfm::format(std::cerr,
"Error during initialization - check debug.log for details\n");
229 #endif // HAVE_DECL_FORK 239 catch (
const std::exception& e) {
258 common::WinCmdLineArgs winArgs;
259 std::tie(argc, argv) = winArgs.get();
284 node.exit_status = EXIT_FAILURE;
289 return node.exit_status;
void InitLogging(const ArgsManager &args)
Initialize global loggers.
static bool ProcessInitCommands(ArgsManager &args)
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
void Close()
Explicit close function.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
bool AppInitLockDirectories()
Lock bitcoin core critical directories.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
std::string LicenseInfo()
Returns licensing information (for -version)
void PrintExceptionContinue(const std::exception *pex, std::string_view thread_name)
const TranslateFn G_TRANSLATION_FUN
Translate string to current locale using Qt.
int TokenWrite(uint8_t token)
Write token to endpoint.
static constexpr bool DEFAULT_DAEMON
Default value for -daemon option.
std::string GetHelpMessage() const
Get the help string.
void SetupServerArgs(ArgsManager &argsman, bool can_listen_ipc)
Register all arguments with the ArgsManager.
bool AppInitBasicSetup(const ArgsManager &args, std::atomic< int > &exit_status)
Initialize bitcoin core: Basic context setup.
std::string SysErrorString(int err)
Return system error string from errno value.
NodeContext struct containing references to chain state and connection state.
bool InitError(const bilingual_str &str)
Show error message.
std::function< std::string(const char *)> TranslateFn
Translate a message to the native language of the user.
int TokenRead()
Read token from endpoint.
bool AppInitMain(NodeContext &node, interfaces::BlockAndHeaderTipInfo *tip_info)
Bitcoin core main initialization.
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...
static bool AppInit(NodeContext &node)
std::string FormatFullVersion()
std::unique_ptr< Init > MakeNodeInit(node::NodeContext &node, int argc, char *argv[], int &exit_status)
Return implementation of Init interface for the node process.
bool AppInitParameterInteraction(const ArgsManager &args)
Initialization: parameter interaction.
bool HelpRequested(const ArgsManager &args)
bool AppInitSanityChecks(const kernel::Context &kernel)
Initialization sanity checks.
static constexpr bool DEFAULT_DAEMONWAIT
Default value for -daemonwait option.
static std::optional< TokenPipe > Make()
Create a new pipe.
void ThreadSetInternalName(const std::string &)
Set the internal (in-memory) name of the current thread only.
bool AppInitInterfaces(NodeContext &node)
Initialize node and wallet interface pointers.
bool IsOpen()
Return whether endpoint is open.
std::optional< ConfigError > InitConfig(ArgsManager &args, SettingsAbortFn settings_abort_fn)
void InitParameterInteraction(ArgsManager &args)
Parameter interaction: change current parameters depending on various rules.
bool IsSwitchChar(char c)
#define Assert(val)
Identity function.
static bool ParseArgs(NodeContext &node, int argc, char *argv[])