@@ -216,7 +216,7 @@ class ArgsManagerHelper {
216216
217217 /* * Determine whether to use config settings in the default section,
218218 * See also comments around ArgsManager::ArgsManager() below. */
219- static inline bool UseDefaultSection (const ArgsManager& am, const std::string& arg)
219+ static inline bool UseDefaultSection (const ArgsManager& am, const std::string& arg) EXCLUSIVE_LOCKS_REQUIRED(am.cs_args)
220220 {
221221 return (am.m_network == CBaseChainParams::MAIN || am.m_network_only_args .count (arg) == 0 );
222222 }
@@ -295,7 +295,7 @@ class ArgsManagerHelper {
295295 /* Special test for -testnet and -regtest args, because we
296296 * don't want to be confused by craziness like "[regtest] testnet=1"
297297 */
298- static inline bool GetNetBoolArg (const ArgsManager &am, const std::string& net_arg)
298+ static inline bool GetNetBoolArg (const ArgsManager &am, const std::string& net_arg) EXCLUSIVE_LOCKS_REQUIRED(am.cs_args)
299299 {
300300 std::pair<bool ,std::string> found_result (false ,std::string ());
301301 found_result = GetArgHelper (am.m_override_args , net_arg, true );
@@ -372,6 +372,8 @@ ArgsManager::ArgsManager() :
372372
373373void ArgsManager::WarnForSectionOnlyArgs ()
374374{
375+ LOCK (cs_args);
376+
375377 // if there's no section selected, don't worry
376378 if (m_network.empty ()) return ;
377379
@@ -400,6 +402,7 @@ void ArgsManager::WarnForSectionOnlyArgs()
400402
401403void ArgsManager::SelectConfigNetwork (const std::string& network)
402404{
405+ LOCK (cs_args);
403406 m_network = network;
404407}
405408
@@ -468,6 +471,7 @@ bool ArgsManager::IsArgKnown(const std::string& key) const
468471 arg_no_net = std::string (" -" ) + key.substr (option_index + 1 , std::string::npos);
469472 }
470473
474+ LOCK (cs_args);
471475 for (const auto & arg_map : m_available_args) {
472476 if (arg_map.second .count (arg_no_net)) return true ;
473477 }
@@ -571,6 +575,7 @@ void ArgsManager::AddArg(const std::string& name, const std::string& help, const
571575 eq_index = name.size ();
572576 }
573577
578+ LOCK (cs_args);
574579 std::map<std::string, Arg>& arg_map = m_available_args[cat];
575580 auto ret = arg_map.emplace (name.substr (0 , eq_index), Arg (name.substr (eq_index, name.size () - eq_index), help, debug_only));
576581 assert (ret.second ); // Make sure an insertion actually happened
@@ -588,6 +593,7 @@ std::string ArgsManager::GetHelpMessage() const
588593 const bool show_debug = gArgs .GetBoolArg (" -help-debug" , false );
589594
590595 std::string usage = " " ;
596+ LOCK (cs_args);
591597 for (const auto & arg_map : m_available_args) {
592598 switch (arg_map.first ) {
593599 case OptionsCategory::OPTIONS:
@@ -880,7 +886,12 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
880886 }
881887 // if there is an -includeconf in the override args, but it is empty, that means the user
882888 // passed '-noincludeconf' on the command line, in which case we should not include anything
883- if (m_override_args.count (" -includeconf" ) == 0 ) {
889+ bool emptyIncludeConf;
890+ {
891+ LOCK (cs_args);
892+ emptyIncludeConf = m_override_args.count (" -includeconf" ) == 0 ;
893+ }
894+ if (emptyIncludeConf) {
884895 std::string chain_id = GetChainName ();
885896 std::vector<std::string> includeconf (GetArgs (" -includeconf" ));
886897 {
@@ -940,6 +951,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
940951
941952std::string ArgsManager::GetChainName () const
942953{
954+ LOCK (cs_args);
943955 bool fRegTest = ArgsManagerHelper::GetNetBoolArg (*this , " -regtest" );
944956 bool fTestNet = ArgsManagerHelper::GetNetBoolArg (*this , " -testnet" );
945957
0 commit comments