From b8abcba74dc501f72089aa70e07e948664b2cedd Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 16 May 2019 22:12:18 +0100 Subject: [PATCH] Fix compilation problem related to getrandom() on non-glibc systems. --- ChangeLog.txt | 1 + lib/util_mosq.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c6f9525e..173b9b4c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -9,6 +9,7 @@ Broker: with glibc >= 2.25. Without this fix, no random numbers would be generated for e.g. on broker client id generation, and so clients connecting expecting this feature would be unable to connect. +- Fix compilation problem related to getrandom() on non-glibc systems. Clients: - Fix -L url parsing when `/topic` part is missing. diff --git a/lib/util_mosq.c b/lib/util_mosq.c index 7c0b6724..ce903e79 100644 --- a/lib/util_mosq.c +++ b/lib/util_mosq.c @@ -28,9 +28,10 @@ Contributors: # include #endif -#if !defined(WITH_TLS) && defined(__linux__) -# if defined(__GLIBC__) && __GLIBC_PREREQ(2, 25) +#if !defined(WITH_TLS) && defined(__linux__) && defined(__GLIBC__) +# if __GLIBC_PREREQ(2, 25) # include +# define HAVE_GETRANDOM 1 # endif #endif @@ -325,7 +326,7 @@ int util__random_bytes(void *bytes, int count) if(RAND_bytes(bytes, count) == 1){ rc = MOSQ_ERR_SUCCESS; } -#elif defined(__GLIBC__) && __GLIBC_PREREQ(2, 25) +#elif defined(HAVE_GETRANDOM) if(getrandom(bytes, count, 0) == count){ rc = MOSQ_ERR_SUCCESS; }