From 948669a7cc168b11783ce46ab365c91574d3532a Mon Sep 17 00:00:00 2001 From: sbbs <> Date: Fri, 10 Apr 2015 22:50:49 +0000 Subject: [PATCH] Don't block on read of /dev/random since on some systems (with no entropy?), this read() call will block indefinitely. Fall-through to pseudo-random seeding if read() fails. Fix for FozzTexx-reported problem on reddit. --- src/sbbs3/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sbbs3/main.cpp b/src/sbbs3/main.cpp index f1d76ddfda..50e03b58a6 100644 --- a/src/sbbs3/main.cpp +++ b/src/sbbs3/main.cpp @@ -297,15 +297,15 @@ DLLEXPORT void DLLCALL sbbs_srand() xp_randomize(); #if defined(HAS_DEV_RANDOM) && defined(RANDOM_DEV) - int rf; + int rf,rd=0; - if((rf=open(RANDOM_DEV, O_RDONLY))!=-1) { - read(rf, &seed, sizeof(seed)); + if((rf=open(RANDOM_DEV, O_RDONLY|O_NONBLOCK))!=-1) { + rd=read(rf, &seed, sizeof(seed)); close(rf); } -#else - seed = time32(NULL) ^ (DWORD)GetCurrentThreadId(); + if(rd != sizeof(seed)) #endif + seed = time32(NULL) ^ (DWORD)GetCurrentThreadId(); srand(seed); sbbs_random(10); /* Throw away first number */ -- GitLab