From c9a06147e66170cd54f8eb28f61e9c2c5e1ad55f Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sun, 8 Dec 2019 19:05:01 +0000 Subject: Extract rng initialisation code to a function. --- src/inspircd.cpp | 15 +++++++++++---- 1 file 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 { -- cgit v1.2.3