Commit 948669a7 authored by sbbs's avatar sbbs
Browse files

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.
parent 02abf23f
......@@ -297,15 +297,15 @@ DLLEXPORT void DLLCALL sbbs_srand()
#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));
seed = time32(NULL) ^ (DWORD)GetCurrentThreadId();
if(rd != sizeof(seed))
seed = time32(NULL) ^ (DWORD)GetCurrentThreadId();
sbbs_random(10); /* Throw away first number */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment