Only use getrandom on recent glibc, when TLS not in use.

pull/1203/head
Roger A. Light 7 years ago
parent 4564ff1232
commit 1a3eaeabce

@ -28,9 +28,11 @@ Contributors:
# include <sys/stat.h>
#endif
#ifdef __linux__
#if !defined(WITH_TLS) && defined(__linux__)
# if defined(__GLIBC__) && __GLIBC_PREREQ(2, 25)
# include <sys/random.h>
# endif
#endif
#ifdef WITH_TLS
# include <openssl/bn.h>
@ -310,8 +312,7 @@ int util__random_bytes(void *bytes, int count)
if(RAND_bytes(bytes, count) == 1){
rc = MOSQ_ERR_SUCCESS;
}
#else
# ifdef __GLIBC__
#elif defined(__GLIBC__) && __GLIBC_PREREQ(2, 25)
if(getrandom(bytes, count, 0) == 0){
rc = MOSQ_ERR_SUCCESS;
}
@ -334,7 +335,6 @@ int util__random_bytes(void *bytes, int count)
((uint8_t *)bytes)[i] = (uint8_t )(random()&0xFF);
}
rc = MOSQ_ERR_SUCCESS;
# endif
#endif
return rc;
}

Loading…
Cancel
Save