diff options
Diffstat (limited to 'src/util.cpp')
| -rw-r--r-- | src/util.cpp | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/src/util.cpp b/src/util.cpp index fc3e846a6..4c9b897f5 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -10,6 +10,7 @@ #endif #include <fcntl.h> #include <sys/stat.h> +#include <sys/resource.h> #endif #include "util.h" @@ -73,8 +74,6 @@ bool fDebug = false; bool fDebugNet = false; bool fPrintToConsole = false; bool fPrintToDebugger = false; -volatile bool fRequestShutdown = false; -bool fShutdown = false; bool fDaemon = false; bool fServer = false; bool fCommandLine = false; @@ -84,6 +83,7 @@ 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; @@ -1049,13 +1049,12 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) static fs::path pathCached[2]; static CCriticalSection csPathCached; - static bool cachedPath[2] = {false, false}; fs::path &path = pathCached[fNetSpecific]; // 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 (cachedPath[fNetSpecific]) + if (fCachedPath[fNetSpecific]) return path; LOCK(csPathCached); @@ -1074,7 +1073,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) fs::create_directory(path); - cachedPath[fNetSpecific]=true; + fCachedPath[fNetSpecific] = true; return path; } @@ -1092,6 +1091,9 @@ 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("*"); @@ -1169,6 +1171,28 @@ bool TruncateFile(FILE *file, unsigned int length) { #endif } + +// this function tries to raise the file descriptor limit to the requested number. +// It returns the actual file descriptor limit (which may be more or less than nMinFD) +int RaiseFileDescriptorLimit(int nMinFD) { +#if defined(WIN32) + return 2048; +#else + struct rlimit limitFD; + if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) { + if (limitFD.rlim_cur < (rlim_t)nMinFD) { + limitFD.rlim_cur = nMinFD; + if (limitFD.rlim_cur > limitFD.rlim_max) + limitFD.rlim_cur = limitFD.rlim_max; + setrlimit(RLIMIT_NOFILE, &limitFD); + getrlimit(RLIMIT_NOFILE, &limitFD); + } + return limitFD.rlim_cur; + } + return nMinFD; // getrlimit failed, assume it's fine +#endif +} + // this function tries to make a particular range of a file allocated (corresponding to disk space) // it is advisory, and the range specified in the arguments will never contain live data void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) { @@ -1233,6 +1257,8 @@ void ShrinkDebugFile() fclose(file); } } + else if(file != NULL) + fclose(file); } @@ -1338,14 +1364,14 @@ void seed_insecure_rand(bool fDeterministic) insecure_rand_Rz = insecure_rand_Rw = 11; } else { uint32_t tmp; - do{ - RAND_bytes((unsigned char*)&tmp,4); - }while(tmp==0 || tmp==0x9068ffffU); - insecure_rand_Rz=tmp; - do{ - RAND_bytes((unsigned char*)&tmp,4); - }while(tmp==0 || tmp==0x464fffffU); - insecure_rand_Rw=tmp; + do { + RAND_bytes((unsigned char*)&tmp, 4); + } while(tmp == 0 || tmp == 0x9068ffffU); + insecure_rand_Rz = tmp; + do { + RAND_bytes((unsigned char*)&tmp, 4); + } while(tmp == 0 || tmp == 0x464fffffU); + insecure_rand_Rw = tmp; } } @@ -1431,9 +1457,12 @@ void RenameThread(const char* name) // removed. pthread_set_name_np(pthread_self(), name); -// This is XCode 10.6-and-later; bring back if we drop 10.5 support: -// #elif defined(MAC_OSX) -// pthread_setname_np(name); +#elif defined(MAC_OSX) && defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + +// pthread_setname_np is XCode 10.6-and-later +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + pthread_setname_np(name); +#endif #else // Prevent warnings for unused parameters... |