diff options
author | Peter Powell <petpow@saberuk.com> | 2019-12-08 19:05:01 +0000 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2019-12-08 19:05:01 +0000 |
commit | c9a06147e66170cd54f8eb28f61e9c2c5e1ad55f (patch) | |
tree | 88749fab88619f880c6e8775e6cc94ac039c4c36 | |
parent | eaa47be7135cf4e70482593bae4ca99f93a6d8d9 (diff) |
Extract rng initialisation code to a function.
-rw-r--r-- | src/inspircd.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 3ce5e553f..8803a9e54 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -87,6 +87,16 @@ namespace delete p; } + // Seeds the random number generator if applicable. + void SeedRng(timespec ts) + { +#if defined _WIN32 + srand(ts.tv_nsec ^ ts.tv_sec); +#elif !defined HAS_ARC4RANDOM_BUF + srandom(ts.tv_nsec ^ ts.tv_sec); +#endif + } + // Required for returning the proper value of EXIT_SUCCESS for the parent process. void VoidSignalHandler(int) { @@ -233,6 +243,7 @@ InspIRCd::InspIRCd(int argc, char** argv) UpdateTime(); this->startup_time = TIME.tv_sec; + SeedRng(TIME); SocketEngine::Init(); this->Config = new ServerConfig; @@ -243,8 +254,6 @@ InspIRCd::InspIRCd(int argc, char** argv) this->Config->cmdline.argc = argc; #ifdef _WIN32 - srand(TIME.tv_nsec ^ TIME.tv_sec); - // Initialize the console values g_hStdout = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO bufinf; @@ -258,8 +267,6 @@ InspIRCd::InspIRCd(int argc, char** argv) g_wOriginalColors = FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN; g_wBackgroundColor = 0; } -#else - srandom(TIME.tv_nsec ^ TIME.tv_sec); #endif { |