diff --git a/ext/random/config.m4 b/ext/random/config.m4 index a8e6d5a568991..bb4214a5c0830 100644 --- a/ext/random/config.m4 +++ b/ext/random/config.m4 @@ -14,6 +14,11 @@ AC_CHECK_HEADERS([CommonCrypto/CommonRandom.h], [], [], #include ]) +dnl +dnl Mostly for non Linux systems +dnl +AC_CHECK_FUNCS([getrandom]) + dnl dnl Setup extension dnl diff --git a/ext/random/random.c b/ext/random/random.c index e30a04259fb2b..576c8412f52f5 100644 --- a/ext/random/random.c +++ b/ext/random/random.c @@ -48,7 +48,7 @@ #if HAVE_SYS_PARAM_H # include -# if (__FreeBSD__ && __FreeBSD_version > 1200000) || (__DragonFly__ && __DragonFly_version >= 500700) || defined(__sun) +# if (__FreeBSD__ && __FreeBSD_version > 1200000) || (__DragonFly__ && __DragonFly_version >= 500700) || (defined(__sun) && defined(HAVE_GETRANDOM)) # include # endif #endif @@ -511,7 +511,7 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw) #else size_t read_bytes = 0; ssize_t n; -# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || defined(__sun) +# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || (defined(__sun) && defined(HAVE_GETRANDOM)) /* Linux getrandom(2) syscall or FreeBSD/DragonFlyBSD getrandom(2) function*/ /* Keep reading until we get enough entropy */ while (read_bytes < size) {