@@ -112,20 +112,30 @@ int fork_daemon(bool nochdir, bool noclose, TokenPipeEnd& endpoint)
112
112
113
113
#endif
114
114
115
- static bool AppInit (NodeContext& node , int argc, char * argv[])
115
+ static bool ParseArgs (ArgsManager& args , int argc, char * argv[])
116
116
{
117
- bool fRet = false ;
118
-
119
- util::ThreadSetInternalName (" init" );
120
-
121
117
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
122
- ArgsManager& args = *Assert (node.args );
123
118
SetupServerArgs (args);
124
119
std::string error;
125
120
if (!args.ParseParameters (argc, argv, error)) {
126
121
return InitError (Untranslated (strprintf (" Error parsing command line arguments: %s" , error)));
127
122
}
128
123
124
+ if (auto error = common::InitConfig (args)) {
125
+ return InitError (error->message , error->details );
126
+ }
127
+
128
+ // Error out when loose non-argument tokens are encountered on command line
129
+ for (int i = 1 ; i < argc; i++) {
130
+ if (!IsSwitchChar (argv[i][0 ])) {
131
+ return InitError (Untranslated (strprintf (" Command line contains unexpected token '%s', see bitcoind -h for a list of options." , argv[i])));
132
+ }
133
+ }
134
+ return true ;
135
+ }
136
+
137
+ static bool ProcessInitCommands (ArgsManager& args)
138
+ {
129
139
// Process help and version before taking care about datadir
130
140
if (HelpRequested (args) || args.IsArgSet (" -version" )) {
131
141
std::string strUsage = PACKAGE_NAME " version " + FormatFullVersion () + " \n " ;
@@ -142,6 +152,14 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
142
152
return true ;
143
153
}
144
154
155
+ return false ;
156
+ }
157
+
158
+ static bool AppInit (NodeContext& node)
159
+ {
160
+ bool fRet = false ;
161
+ ArgsManager& args = *Assert (node.args );
162
+
145
163
#if HAVE_DECL_FORK
146
164
// Communication with parent after daemonizing. This is used for signalling in the following ways:
147
165
// - a boolean token is sent when the initialization process (all the Init* functions) have finished to indicate
@@ -153,17 +171,6 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
153
171
std::any context{&node};
154
172
try
155
173
{
156
- if (auto error = common::InitConfig (args)) {
157
- return InitError (error->message , error->details );
158
- }
159
-
160
- // Error out when loose non-argument tokens are encountered on command line
161
- for (int i = 1 ; i < argc; i++) {
162
- if (!IsSwitchChar (argv[i][0 ])) {
163
- return InitError (Untranslated (strprintf (" Command line contains unexpected token '%s', see bitcoind -h for a list of options." , argv[i])));
164
- }
165
- }
166
-
167
174
// -server defaults to true for bitcoind but not for the GUI so do this here
168
175
args.SoftSetBoolArg (" -server" , true );
169
176
// Set this early so that parameter interactions go to console
@@ -236,14 +243,6 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
236
243
}
237
244
#endif
238
245
SetSyscallSandboxPolicy (SyscallSandboxPolicy::SHUTOFF);
239
- if (fRet ) {
240
- WaitForShutdown ();
241
- } else {
242
- node.exit_status = EXIT_FAILURE;
243
- }
244
- Interrupt (node);
245
- Shutdown (node);
246
-
247
246
return fRet ;
248
247
}
249
248
@@ -266,5 +265,22 @@ MAIN_FUNCTION
266
265
// Connect bitcoind signal handlers
267
266
noui_connect ();
268
267
269
- return AppInit (node, argc, argv) ? node.exit_status .load () : EXIT_FAILURE;
268
+ util::ThreadSetInternalName (" init" );
269
+
270
+ // Interpret command line arguments
271
+ ArgsManager& args = *Assert (node.args );
272
+ if (!ParseArgs (args, argc, argv)) return EXIT_FAILURE;
273
+ // Process early info return commands such as -help or -version
274
+ if (ProcessInitCommands (args)) return EXIT_SUCCESS;
275
+
276
+ // Start application
277
+ if (AppInit (node)) {
278
+ WaitForShutdown ();
279
+ } else {
280
+ node.exit_status = EXIT_FAILURE;
281
+ }
282
+ Interrupt (node);
283
+ Shutdown (node);
284
+
285
+ return node.exit_status ;
270
286
}
0 commit comments