diff --git a/src/util/system.h b/src/util/system.h --- a/src/util/system.h +++ b/src/util/system.h @@ -148,11 +148,14 @@ }; mutable CCriticalSection cs_args; - std::map> m_override_args; - std::map> m_config_args; - std::string m_network; - std::set m_network_only_args; - std::map> m_available_args; + std::map> + m_override_args GUARDED_BY(cs_args); + std::map> + m_config_args GUARDED_BY(cs_args); + std::string m_network GUARDED_BY(cs_args); + std::set m_network_only_args GUARDED_BY(cs_args); + std::map> + m_available_args GUARDED_BY(cs_args); bool ReadConfigStream(std::istream &stream, std::string &error, bool ignore_invalid_keys = false); @@ -275,7 +278,10 @@ /** * Clear available arguments */ - void ClearArgs() { m_available_args.clear(); } + void ClearArgs() { + LOCK(cs_args); + m_available_args.clear(); + } /** * Get the help string diff --git a/src/util/system.cpp b/src/util/system.cpp --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -195,7 +195,8 @@ /** Determine whether to use config settings in the default section, * See also comments around ArgsManager::ArgsManager() below. */ static inline bool UseDefaultSection(const ArgsManager &am, - const std::string &arg) { + const std::string &arg) + EXCLUSIVE_LOCKS_REQUIRED(am.cs_args) { return (am.m_network == CBaseChainParams::MAIN || am.m_network_only_args.count(arg) == 0); } @@ -279,7 +280,8 @@ * confused by craziness like "[regtest] testnet=1" */ static inline bool GetNetBoolArg(const ArgsManager &am, - const std::string &net_arg) { + const std::string &net_arg) + EXCLUSIVE_LOCKS_REQUIRED(am.cs_args) { std::pair found_result(false, std::string()); found_result = GetArgHelper(am.m_override_args, net_arg, true); if (!found_result.first) { @@ -353,6 +355,8 @@ } void ArgsManager::WarnForSectionOnlyArgs() { + LOCK(cs_args); + // if there's no section selected, don't worry if (m_network.empty()) { return; @@ -393,6 +397,7 @@ } void ArgsManager::SelectConfigNetwork(const std::string &network) { + LOCK(cs_args); m_network = network; } @@ -473,6 +478,7 @@ std::string("-") + key.substr(option_index + 1, std::string::npos); } + LOCK(cs_args); for (const auto &arg_map : m_available_args) { if (arg_map.second.count(arg_no_net)) { return true; @@ -616,6 +622,7 @@ eq_index = name.size(); } + LOCK(cs_args); std::map &arg_map = m_available_args[cat]; auto ret = arg_map.emplace( name.substr(0, eq_index), @@ -634,6 +641,7 @@ const bool show_debug = gArgs.GetBoolArg("-help-debug", false); std::string usage = ""; + LOCK(cs_args); for (const auto &arg_map : m_available_args) { switch (arg_map.first) { case OptionsCategory::OPTIONS: @@ -1014,6 +1022,7 @@ } std::string ArgsManager::GetChainName() const { + LOCK(cs_args); bool fRegTest = ArgsManagerHelper::GetNetBoolArg(*this, "-regtest"); bool fTestNet = ArgsManagerHelper::GetNetBoolArg(*this, "-testnet");