Changeset View
Changeset View
Standalone View
Standalone View
src/util/system.cpp
Show All 14 Lines | |||||
#include <random.h> | #include <random.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/time.h> | #include <util/time.h> | ||||
#include <boost/interprocess/sync/file_lock.hpp> | #include <boost/interprocess/sync/file_lock.hpp> | ||||
#include <boost/thread.hpp> | #include <boost/thread.hpp> | ||||
#include <openssl/conf.h> | |||||
#include <openssl/rand.h> | |||||
#include <cstdarg> | #include <cstdarg> | ||||
#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) | #if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) | ||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <pthread_np.h> | #include <pthread_np.h> | ||||
#endif | #endif | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
// Application startup time (used for uptime calculation) | // Application startup time (used for uptime calculation) | ||||
const int64_t nStartupTime = GetTime(); | const int64_t nStartupTime = GetTime(); | ||||
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"; | ||||
ArgsManager gArgs; | ArgsManager gArgs; | ||||
/** Init OpenSSL library multithreading support */ | |||||
static std::unique_ptr<CCriticalSection[]> ppmutexOpenSSL; | |||||
void locking_callback(int mode, int i, const char *file, | |||||
int line) NO_THREAD_SAFETY_ANALYSIS { | |||||
if (mode & CRYPTO_LOCK) { | |||||
ENTER_CRITICAL_SECTION(ppmutexOpenSSL[i]); | |||||
} else { | |||||
LEAVE_CRITICAL_SECTION(ppmutexOpenSSL[i]); | |||||
} | |||||
} | |||||
// Singleton for wrapping OpenSSL setup/teardown. | |||||
class CInit { | |||||
public: | |||||
CInit() { | |||||
// Init OpenSSL library multithreading support. | |||||
ppmutexOpenSSL.reset(new CCriticalSection[CRYPTO_num_locks()]); | |||||
CRYPTO_set_locking_callback(locking_callback); | |||||
// OpenSSL can optionally load a config file which lists optional | |||||
// loadable modules and engines. We don't use them so we don't require | |||||
// the config. However some of our libs may call functions which attempt | |||||
// to load the config file, possibly resulting in an exit() or crash if | |||||
// it is missing or corrupt. Explicitly tell OpenSSL not to try to load | |||||
// the file. The result for our libs will be that the config appears to | |||||
// have been loaded and there are no modules/engines available. | |||||
OPENSSL_no_config(); | |||||
#ifdef WIN32 | |||||
// Seed OpenSSL PRNG with current contents of the screen. | |||||
RAND_screen(); | |||||
#endif | |||||
// Seed OpenSSL PRNG with performance counter. | |||||
RandAddSeed(); | |||||
} | |||||
~CInit() { | |||||
// Securely erase the memory used by the PRNG. | |||||
RAND_cleanup(); | |||||
// Shutdown OpenSSL library multithreading support. | |||||
CRYPTO_set_locking_callback(nullptr); | |||||
// Clear the set of locks now to maintain symmetry with the constructor. | |||||
ppmutexOpenSSL.reset(); | |||||
} | |||||
} instance_of_cinit; | |||||
/** | /** | ||||
* A map that contains all the currently held directory locks. After successful | * A map that contains all the currently held directory locks. After successful | ||||
* locking, these will be held here until the global destructor cleans them up | * locking, these will be held here until the global destructor cleans them up | ||||
* and thus automatically unlocks them, or ReleaseDirectoryLocks is called. | * and thus automatically unlocks them, or ReleaseDirectoryLocks is called. | ||||
*/ | */ | ||||
static std::map<std::string, std::unique_ptr<boost::interprocess::file_lock>> | static std::map<std::string, std::unique_ptr<boost::interprocess::file_lock>> | ||||
dir_locks; | dir_locks; | ||||
/** Mutex to protect dir_locks. */ | /** Mutex to protect dir_locks. */ | ||||
▲ Show 20 Lines • Show All 1,230 Lines • Show Last 20 Lines |