@@ -107,14 +107,14 @@ static const char* DEFAULT_ASMAP_FILENAME="ip_asn.map";
107
107
*/
108
108
static const char * BITCOIN_PID_FILENAME = " bitcoind.pid" ;
109
109
110
- static fs::path GetPidFile ()
110
+ static fs::path GetPidFile (const ArgsManager& args )
111
111
{
112
112
return AbsPathForConfigVal (fs::path (gArgs .GetArg (" -pid" , BITCOIN_PID_FILENAME)));
113
113
}
114
114
115
- NODISCARD static bool CreatePidFile ()
115
+ NODISCARD static bool CreatePidFile (const ArgsManager& args )
116
116
{
117
- fsbridge::ofstream file{GetPidFile ()};
117
+ fsbridge::ofstream file{GetPidFile (args )};
118
118
if (file) {
119
119
#ifdef WIN32
120
120
tfm::format (file, " %d\n " , GetCurrentProcessId ());
@@ -123,7 +123,7 @@ NODISCARD static bool CreatePidFile()
123
123
#endif
124
124
return true ;
125
125
} else {
126
- return InitError (strprintf (_ (" Unable to create the PID file '%s': %s" ), GetPidFile ().string (), std::strerror (errno)));
126
+ return InitError (strprintf (_ (" Unable to create the PID file '%s': %s" ), GetPidFile (args ).string (), std::strerror (errno)));
127
127
}
128
128
}
129
129
@@ -180,6 +180,7 @@ void Shutdown(NodeContext& node)
180
180
TRY_LOCK (g_shutdown_mutex, lock_shutdown);
181
181
if (!lock_shutdown) return ;
182
182
LogPrintf (" %s: In progress...\n " , __func__);
183
+ Assert (node.args );
183
184
184
185
// / Note: Shutdown() must be able to handle cases in which initialization failed part of the way,
185
186
// / for example if the data directory was found to be locked.
@@ -230,7 +231,7 @@ void Shutdown(NodeContext& node)
230
231
node.connman .reset ();
231
232
node.banman .reset ();
232
233
233
- if (::mempool.IsLoaded () && gArgs . GetArg (" -persistmempool" , DEFAULT_PERSIST_MEMPOOL)) {
234
+ if (::mempool.IsLoaded () && node. args -> GetArg (" -persistmempool" , DEFAULT_PERSIST_MEMPOOL)) {
234
235
DumpMempool (::mempool);
235
236
}
236
237
@@ -301,19 +302,19 @@ void Shutdown(NodeContext& node)
301
302
GetMainSignals ().UnregisterBackgroundSignalScheduler ();
302
303
globalVerifyHandle.reset ();
303
304
ECC_Stop ();
304
- node.args = nullptr ;
305
305
node.mempool = nullptr ;
306
306
node.chainman = nullptr ;
307
307
node.scheduler .reset ();
308
308
309
309
try {
310
- if (!fs::remove (GetPidFile ())) {
310
+ if (!fs::remove (GetPidFile (*node. args ))) {
311
311
LogPrintf (" %s: Unable to remove PID file: File does not exist\n " , __func__);
312
312
}
313
313
} catch (const fs::filesystem_error& e) {
314
314
LogPrintf (" %s: Unable to remove PID file: %s\n " , __func__, fsbridge::get_filesystem_error_message (e));
315
315
}
316
316
317
+ node.args = nullptr ;
317
318
LogPrintf (" %s: done\n " , __func__);
318
319
}
319
320
@@ -372,7 +373,7 @@ void SetupServerArgs(NodeContext& node)
372
373
node.args = &gArgs ;
373
374
ArgsManager& argsman = *node.args ;
374
375
375
- SetupHelpOptions (gArgs );
376
+ SetupHelpOptions (argsman );
376
377
argsman.AddArg (" -help-debug" , " Print help message with debugging options and exit" , ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); // server-only for now
377
378
378
379
const auto defaultBaseParams = CreateBaseChainParams (CBaseChainParams::MAIN);
@@ -684,7 +685,7 @@ static void CleanupBlockRevFiles()
684
685
}
685
686
}
686
687
687
- static void ThreadImport (ChainstateManager& chainman, std::vector<fs::path> vImportFiles)
688
+ static void ThreadImport (ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args )
688
689
{
689
690
const CChainParams& chainparams = Params ();
690
691
ScheduleBatchPriority ();
@@ -780,6 +781,7 @@ static bool InitSanityCheck()
780
781
781
782
static bool AppInitServers (const util::Ref& context, NodeContext& node)
782
783
{
784
+ const ArgsManager& args = *Assert (node.args );
783
785
RPCServer::OnStarted (&OnRPCStarted);
784
786
RPCServer::OnStopped (&OnRPCStopped);
785
787
if (!InitHTTPServer ())
@@ -794,7 +796,7 @@ static bool AppInitServers(const util::Ref& context, NodeContext& node)
794
796
}
795
797
796
798
// Parameter interaction based on rules
797
- void InitParameterInteraction ()
799
+ void InitParameterInteraction (ArgsManager& args )
798
800
{
799
801
// when specifying an explicit binding address, you want to listen on it
800
802
// even when -connect or -proxy is specified
@@ -863,7 +865,7 @@ void InitParameterInteraction()
863
865
* Note that this is called very early in the process lifetime, so you should be
864
866
* careful about what global state you rely on here.
865
867
*/
866
- void InitLogging ()
868
+ void InitLogging (const ArgsManager& args )
867
869
{
868
870
LogInstance ().m_print_to_file = !gArgs .IsArgNegated (" -debuglogfile" );
869
871
LogInstance ().m_file_path = AbsPathForConfigVal (gArgs .GetArg (" -debuglogfile" , DEFAULT_DEBUGLOGFILE));
@@ -909,7 +911,7 @@ std::set<BlockFilterType> g_enabled_filter_types;
909
911
std::terminate ();
910
912
};
911
913
912
- bool AppInitBasicSetup ()
914
+ bool AppInitBasicSetup (ArgsManager& args )
913
915
{
914
916
// ********************************************************* Step 1: setup
915
917
#ifdef _MSC_VER
@@ -951,7 +953,7 @@ bool AppInitBasicSetup()
951
953
return true ;
952
954
}
953
955
954
- bool AppInitParameterInteraction ()
956
+ bool AppInitParameterInteraction (const ArgsManager& args )
955
957
{
956
958
const CChainParams& chainparams = Params ();
957
959
// ********************************************************* Step 2: parameter interactions
@@ -1247,9 +1249,10 @@ bool AppInitLockDataDirectory()
1247
1249
1248
1250
bool AppInitMain (const util::Ref& context, NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
1249
1251
{
1252
+ const ArgsManager& args = *Assert (node.args );
1250
1253
const CChainParams& chainparams = Params ();
1251
1254
// ********************************************************* Step 4a: application initialization
1252
- if (!CreatePidFile ()) {
1255
+ if (!CreatePidFile (args )) {
1253
1256
// Detailed error printed inside CreatePidFile().
1254
1257
return false ;
1255
1258
}
@@ -1853,7 +1856,9 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
1853
1856
vImportFiles.push_back (strFile);
1854
1857
}
1855
1858
1856
- g_load_block = std::thread (&TraceThread<std::function<void ()>>, " loadblk" , [=, &chainman]{ ThreadImport (chainman, vImportFiles); });
1859
+ g_load_block = std::thread (&TraceThread<std::function<void ()>>, " loadblk" , [=, &chainman, &args] {
1860
+ ThreadImport (chainman, vImportFiles, args);
1861
+ });
1857
1862
1858
1863
// Wait for genesis block to be processed
1859
1864
{
0 commit comments