From e9d0a431cb012363b80c1a0437e9f21bfd8d1b35 Mon Sep 17 00:00:00 2001 From: Cizzle Date: Thu, 13 Dec 2018 21:32:29 +0100 Subject: [PATCH] Fix getrandom() syscall not existing while function exists in header Found by: jack3 Patch by: Cizzle On systems running Linux older than 3.17 and using glibc 2.25 or newer, the getrandom() function exists in the system header but the system call does not exist. This checks and skips the call if not found. (cherry picked from commit 2962dd20cc174a723a6fa621b8d6e4795b8e345b) --- src/main.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 44ef1660e..8510b2c8e 100644 --- a/src/main.c +++ b/src/main.c @@ -1021,12 +1021,20 @@ int mainloop(int toplevel) static void init_random(void) { unsigned int seed; #ifdef HAVE_GETRANDOM - if (getrandom(&seed, sizeof(seed), 0) != sizeof(seed)) - fatal("ERROR: getrandom()\n", 0); -#else - struct timeval tp; - gettimeofday(&tp, NULL); - seed = (tp.tv_sec * tp.tv_usec) ^ getpid(); + if (getrandom(&seed, sizeof(seed), 0) != sizeof(seed)) { + if (errno != ENOSYS) { + fatal("ERROR: getrandom()\n", 0); + } else { + /* getrandom() is available in header but syscall is not! + * This can happen with glibc>=2.25 and linux<3.17 + */ +#endif + struct timeval tp; + gettimeofday(&tp, NULL); + seed = (tp.tv_sec * tp.tv_usec) ^ getpid(); +#ifdef HAVE_GETRANDOM + } + } #endif srandom(seed); }