diff options
author | Matt Corallo <git@bluematt.me> | 2016-11-29 18:52:44 -0800 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2016-12-24 11:29:33 -0500 |
commit | 4e048142a5e45d622355dad92ade192ad4769ca3 (patch) | |
tree | 838431696a4bdc3b78d0172bffbefd0220c86407 /src | |
parent | 4cd373aea8d20356727f7d65e0bc818beb6523dc (diff) | |
download | bitcoin-4e048142a5e45d622355dad92ade192ad4769ca3.tar.xz |
Lock mapArgs/mapMultiArgs access in util
Diffstat (limited to 'src')
-rw-r--r-- | src/util.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/util.cpp b/src/util.cpp index 0a5a899997..e3697183da 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -102,6 +102,7 @@ using namespace std; const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf"; const char * const BITCOIN_PID_FILENAME = "bitcoind.pid"; +CCriticalSection cs_args; map<string, string> mapArgs; static map<string, vector<string> > _mapMultiArgs; const map<string, vector<string> >& mapMultiArgs = _mapMultiArgs; @@ -346,6 +347,7 @@ static void InterpretNegativeSetting(std::string& strKey, std::string& strValue) void ParseParameters(int argc, const char* const argv[]) { + LOCK(cs_args); mapArgs.clear(); _mapMultiArgs.clear(); @@ -381,11 +383,13 @@ void ParseParameters(int argc, const char* const argv[]) bool IsArgSet(const std::string& strArg) { + LOCK(cs_args); return mapArgs.count(strArg); } std::string GetArg(const std::string& strArg, const std::string& strDefault) { + LOCK(cs_args); if (mapArgs.count(strArg)) return mapArgs[strArg]; return strDefault; @@ -393,6 +397,7 @@ std::string GetArg(const std::string& strArg, const std::string& strDefault) int64_t GetArg(const std::string& strArg, int64_t nDefault) { + LOCK(cs_args); if (mapArgs.count(strArg)) return atoi64(mapArgs[strArg]); return nDefault; @@ -400,6 +405,7 @@ int64_t GetArg(const std::string& strArg, int64_t nDefault) bool GetBoolArg(const std::string& strArg, bool fDefault) { + LOCK(cs_args); if (mapArgs.count(strArg)) return InterpretBool(mapArgs[strArg]); return fDefault; @@ -407,6 +413,7 @@ bool GetBoolArg(const std::string& strArg, bool fDefault) bool SoftSetArg(const std::string& strArg, const std::string& strValue) { + LOCK(cs_args); if (mapArgs.count(strArg)) return false; mapArgs[strArg] = strValue; @@ -522,6 +529,8 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) void ClearDatadirCache() { + LOCK(csPathCached); + pathCached = boost::filesystem::path(); pathCachedNetSpecific = boost::filesystem::path(); } @@ -541,18 +550,21 @@ void ReadConfigFile(const std::string& confPath) if (!streamConfig.good()) return; // No bitcoin.conf file is OK - set<string> setOptions; - setOptions.insert("*"); - - for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it) { - // Don't overwrite existing settings so command line settings override bitcoin.conf - string strKey = string("-") + it->string_key; - string strValue = it->value[0]; - InterpretNegativeSetting(strKey, strValue); - if (mapArgs.count(strKey) == 0) - mapArgs[strKey] = strValue; - _mapMultiArgs[strKey].push_back(strValue); + LOCK(cs_args); + set<string> setOptions; + setOptions.insert("*"); + + for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it) + { + // Don't overwrite existing settings so command line settings override bitcoin.conf + string strKey = string("-") + it->string_key; + string strValue = it->value[0]; + InterpretNegativeSetting(strKey, strValue); + if (mapArgs.count(strKey) == 0) + mapArgs[strKey] = strValue; + _mapMultiArgs[strKey].push_back(strValue); + } } // If datadir is changed in .conf file: ClearDatadirCache(); |