Browse Source

Lock mapArgs/mapMultiArgs access in util

0.14
Matt Corallo 8 years ago
parent
commit
4e048142a5
  1. 34
      src/util.cpp

34
src/util.cpp

@ -102,6 +102,7 @@ using namespace std;
const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf"; const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf";
const char * const BITCOIN_PID_FILENAME = "bitcoind.pid"; const char * const BITCOIN_PID_FILENAME = "bitcoind.pid";
CCriticalSection cs_args;
map<string, string> mapArgs; map<string, string> mapArgs;
static map<string, vector<string> > _mapMultiArgs; static map<string, vector<string> > _mapMultiArgs;
const map<string, vector<string> >& mapMultiArgs = _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[]) void ParseParameters(int argc, const char* const argv[])
{ {
LOCK(cs_args);
mapArgs.clear(); mapArgs.clear();
_mapMultiArgs.clear(); _mapMultiArgs.clear();
@ -381,11 +383,13 @@ void ParseParameters(int argc, const char* const argv[])
bool IsArgSet(const std::string& strArg) bool IsArgSet(const std::string& strArg)
{ {
LOCK(cs_args);
return mapArgs.count(strArg); return mapArgs.count(strArg);
} }
std::string GetArg(const std::string& strArg, const std::string& strDefault) std::string GetArg(const std::string& strArg, const std::string& strDefault)
{ {
LOCK(cs_args);
if (mapArgs.count(strArg)) if (mapArgs.count(strArg))
return mapArgs[strArg]; return mapArgs[strArg];
return strDefault; 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) int64_t GetArg(const std::string& strArg, int64_t nDefault)
{ {
LOCK(cs_args);
if (mapArgs.count(strArg)) if (mapArgs.count(strArg))
return atoi64(mapArgs[strArg]); return atoi64(mapArgs[strArg]);
return nDefault; return nDefault;
@ -400,6 +405,7 @@ int64_t GetArg(const std::string& strArg, int64_t nDefault)
bool GetBoolArg(const std::string& strArg, bool fDefault) bool GetBoolArg(const std::string& strArg, bool fDefault)
{ {
LOCK(cs_args);
if (mapArgs.count(strArg)) if (mapArgs.count(strArg))
return InterpretBool(mapArgs[strArg]); return InterpretBool(mapArgs[strArg]);
return fDefault; return fDefault;
@ -407,6 +413,7 @@ bool GetBoolArg(const std::string& strArg, bool fDefault)
bool SoftSetArg(const std::string& strArg, const std::string& strValue) bool SoftSetArg(const std::string& strArg, const std::string& strValue)
{ {
LOCK(cs_args);
if (mapArgs.count(strArg)) if (mapArgs.count(strArg))
return false; return false;
mapArgs[strArg] = strValue; mapArgs[strArg] = strValue;
@ -522,6 +529,8 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
void ClearDatadirCache() void ClearDatadirCache()
{ {
LOCK(csPathCached);
pathCached = boost::filesystem::path(); pathCached = boost::filesystem::path();
pathCachedNetSpecific = boost::filesystem::path(); pathCachedNetSpecific = boost::filesystem::path();
} }
@ -541,18 +550,21 @@ void ReadConfigFile(const std::string& confPath)
if (!streamConfig.good()) if (!streamConfig.good())
return; // No bitcoin.conf file is OK 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 LOCK(cs_args);
string strKey = string("-") + it->string_key; set<string> setOptions;
string strValue = it->value[0]; setOptions.insert("*");
InterpretNegativeSetting(strKey, strValue);
if (mapArgs.count(strKey) == 0) for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
mapArgs[strKey] = strValue; {
_mapMultiArgs[strKey].push_back(strValue); // 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: // If datadir is changed in .conf file:
ClearDatadirCache(); ClearDatadirCache();

Loading…
Cancel
Save