summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.in7
-rw-r--r--misc/unix/rand.c23
2 files changed, 28 insertions, 2 deletions
diff --git a/configure.in b/configure.in
index 7ab0ec2f1..cfd400144 100644
--- a/configure.in
+++ b/configure.in
@@ -2456,6 +2456,10 @@ dnl ----------------------------- Checking for /dev/random
AC_CHECK_HEADERS(sys/random.h)
AC_CHECK_FUNCS(getrandom)
+AC_CHECK_HEADERS(sys/syscall.h)
+AC_CHECK_HEADERS(linux/random.h)
+AC_CHECK_DECLS([SYS_getrandom], [], [], [#include <sys/syscall.h>])
+
AC_CHECK_FUNCS(arc4random_buf)
AC_MSG_CHECKING(for entropy source)
@@ -2479,6 +2483,9 @@ if test "$rand" != "1"; then
if test "$ac_cv_func_getrandom" = yes; then
AC_MSG_RESULT(getrandom)
rand="1"
+ elif test "$ac_cv_have_decl_SYS_getrandom" = yes; then
+ AC_MSG_RESULT(SYS_getrandom)
+ rand="1"
fi
fi
diff --git a/misc/unix/rand.c b/misc/unix/rand.c
index 89ffe2550..449819a21 100644
--- a/misc/unix/rand.c
+++ b/misc/unix/rand.c
@@ -42,9 +42,28 @@
#elif defined(HAVE_SYS_UUID_H)
#include <sys/uuid.h>
#endif
-#ifdef HAVE_GETRANDOM
+
+#if defined(HAVE_SYS_RANDOM_H)
+
#include <sys/random.h>
+#define USE_GETRANDOM
+
+#elif defined(HAVE_SYS_SYSCALL_H) && \
+ defined(HAVE_LINUX_RANDOM_H) && \
+ HAVE_DECL_SYS_GETRANDOM
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
#endif
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <linux/random.h>
+
+#define getrandom(buf, buflen, flags) \
+ syscall(SYS_getrandom, (buf), (buflen), (flags))
+#define USE_GETRANDOM
+
+#endif /* HAVE_SYS_RANDOM_H */
#ifndef SHUT_RDWR
#define SHUT_RDWR 2
@@ -90,7 +109,7 @@ APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data)
APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char *buf,
apr_size_t length)
{
-#if defined(HAVE_GETRANDOM)
+#if defined(USE_GETRANDOM)
do {
int rc;