diff options
Diffstat (limited to 'src/util.cpp')
| -rw-r--r-- | src/util.cpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/util.cpp b/src/util.cpp index bfb6d7583..136a03548 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -8,6 +8,7 @@ #ifdef __linux__ #define _POSIX_C_SOURCE 200112L #endif +#include <algorithm> #include <fcntl.h> #include <sys/stat.h> #include <sys/resource.h> @@ -83,7 +84,6 @@ bool fNoListen = false; bool fLogTimestamps = false; CMedianFilter<int64> vTimeOffsets(200,0); volatile bool fReopenDebugLog = false; -bool fCachedPath[2] = {false, false}; // Init OpenSSL library multithreading support static CCriticalSection** ppmutexOpenSSL; @@ -311,7 +311,7 @@ string vstrprintf(const char *format, va_list ap) char* p = buffer; int limit = sizeof(buffer); int ret; - loop + while (true) { va_list arg_ptr; va_copy(arg_ptr, ap); @@ -371,7 +371,7 @@ void ParseString(const string& str, char c, vector<string>& v) return; string::size_type i1 = 0; string::size_type i2; - loop + while (true) { i2 = str.find(c, i1); if (i2 == str.npos) @@ -487,7 +487,7 @@ vector<unsigned char> ParseHex(const char* psz) { // convert hex dump to vector vector<unsigned char> vch; - loop + while (true) { while (isspace(*psz)) psz++; @@ -941,7 +941,7 @@ string DecodeBase32(const string& str) bool WildcardMatch(const char* psz, const char* mask) { - loop + while (true) { switch (*mask) { @@ -1043,22 +1043,25 @@ boost::filesystem::path GetDefaultDataDir() #endif } +static boost::filesystem::path pathCached[CChainParams::MAX_NETWORK_TYPES+1]; +static CCriticalSection csPathCached; + const boost::filesystem::path &GetDataDir(bool fNetSpecific) { namespace fs = boost::filesystem; - static fs::path pathCached[2]; - static CCriticalSection csPathCached; + LOCK(csPathCached); + + int nNet = CChainParams::MAX_NETWORK_TYPES; + if (fNetSpecific) nNet = Params().NetworkID(); - fs::path &path = pathCached[fNetSpecific]; + fs::path &path = pathCached[nNet]; // This can be called during exceptions by printf, so we cache the // value so we don't have to do memory allocations after that. - if (fCachedPath[fNetSpecific]) + if (!path.empty()) return path; - LOCK(csPathCached); - if (mapArgs.count("-datadir")) { path = fs::system_complete(mapArgs["-datadir"]); if (!fs::is_directory(path)) { @@ -1073,10 +1076,15 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) fs::create_directories(path); - fCachedPath[fNetSpecific] = true; return path; } +void ClearDatadirCache() +{ + std::fill(&pathCached[0], &pathCached[CChainParams::MAX_NETWORK_TYPES+1], + boost::filesystem::path()); +} + boost::filesystem::path GetConfigFile() { boost::filesystem::path pathConfigFile(GetArg("-conf", "bitcoin.conf")); @@ -1091,9 +1099,6 @@ void ReadConfigFile(map<string, string>& mapSettingsRet, if (!streamConfig.good()) return; // No bitcoin.conf file is OK - // clear path cache after loading config file - fCachedPath[0] = fCachedPath[1] = false; - set<string> setOptions; setOptions.insert("*"); @@ -1109,6 +1114,8 @@ void ReadConfigFile(map<string, string>& mapSettingsRet, } mapMultiSettingsRet[strKey].push_back(it->value[0]); } + // If datadir is changed in .conf file: + ClearDatadirCache(); } boost::filesystem::path GetPidFile() @@ -1118,6 +1125,7 @@ boost::filesystem::path GetPidFile() return pathPidFile; } +#ifndef WIN32 void CreatePidFile(const boost::filesystem::path &path, pid_t pid) { FILE* file = fopen(path.string().c_str(), "w"); @@ -1127,6 +1135,7 @@ void CreatePidFile(const boost::filesystem::path &path, pid_t pid) fclose(file); } } +#endif bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest) { |