| 109 | #endif |
| 110 | |
| 111 | static bool AppInit(NodeContext& node, int argc, char* argv[]) |
| 112 | { |
| 113 | bool fRet = false; |
| 114 | |
| 115 | util::ThreadSetInternalName("init"); |
| 116 | |
| 117 | // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main() |
| 118 | ArgsManager& args = *Assert(node.args); |
| 119 | SetupServerArgs(args); |
| 120 | std::string error; |
| 121 | if (!args.ParseParameters(argc, argv, error)) { |
| 122 | return InitError(Untranslated(strprintf("Error parsing command line arguments: %s\n", error))); |
| 123 | } |
| 124 | |
| 125 | // Process help and version before taking care about datadir |
| 126 | if (HelpRequested(args) || args.IsArgSet("-version")) { |
| 127 | std::string strUsage = PACKAGE_NAME " version " + FormatFullVersion() + "\n"; |
| 128 | |
| 129 | if (args.IsArgSet("-version")) { |
| 130 | strUsage += FormatParagraph(LicenseInfo()); |
| 131 | } else { |
| 132 | strUsage += "\nUsage: elementsd [options] Start " PACKAGE_NAME "\n" |
| 133 | "\n"; |
| 134 | strUsage += args.GetHelpMessage(); |
| 135 | } |
| 136 | |
| 137 | tfm::format(std::cout, "%s", strUsage); |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | #if HAVE_DECL_FORK |
| 142 | // Communication with parent after daemonizing. This is used for signalling in the following ways: |
| 143 | // - a boolean token is sent when the initialization process (all the Init* functions) have finished to indicate |
| 144 | // that the parent process can quit, and whether it was successful/unsuccessful. |
| 145 | // - an unexpected shutdown of the child process creates an unexpected end of stream at the parent |
| 146 | // end, which is interpreted as failure to start. |
| 147 | TokenPipeEnd daemon_ep; |
| 148 | #endif |
| 149 | std::any context{&node}; |
| 150 | try |
| 151 | { |
| 152 | if (!CheckDataDirOption()) { |
| 153 | return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", args.GetArg("-datadir", "")))); |
| 154 | } |
| 155 | if (!args.ReadConfigFiles(error, true)) { |
| 156 | return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error))); |
| 157 | } |
| 158 | // Check for chain settings (Params() calls are only valid after this clause) |
| 159 | try { |
| 160 | SelectParams(args.GetChainName()); |
| 161 | } catch (const std::exception& e) { |
| 162 | return InitError(Untranslated(strprintf("%s\n", e.what()))); |
| 163 | } |
| 164 | |
| 165 | // Error out when loose non-argument tokens are encountered on command line |
| 166 | for (int i = 1; i < argc; i++) { |
| 167 | if (!IsSwitchChar(argv[i][0])) { |
| 168 | return InitError(Untranslated(strprintf("Command line contains unexpected token '%s', see elementsd -h for a list of options.\n", argv[i]))); |
no test coverage detected