You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2017/11/04 22:02:54 UTC

svn commit: r1814326 - in /apr/apr/trunk: configure.in misc/unix/rand.c

Author: ylavic
Date: Sat Nov  4 22:02:54 2017
New Revision: 1814326

URL: http://svn.apache.org/viewvc?rev=1814326&view=rev
Log:
rand: follow up to r1814240.

Fall back to using SYS_getrandom syscall when it's available in linux (3.17+)
but not in glibc (2.25+, not very deployed yet).

Modified:
    apr/apr/trunk/configure.in
    apr/apr/trunk/misc/unix/rand.c

Modified: apr/apr/trunk/configure.in
URL: http://svn.apache.org/viewvc/apr/apr/trunk/configure.in?rev=1814326&r1=1814325&r2=1814326&view=diff
==============================================================================
--- apr/apr/trunk/configure.in (original)
+++ apr/apr/trunk/configure.in Sat Nov  4 22:02:54 2017
@@ -2456,6 +2456,10 @@ dnl ----------------------------- Checki
 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
 

Modified: apr/apr/trunk/misc/unix/rand.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/misc/unix/rand.c?rev=1814326&r1=1814325&r2=1814326&view=diff
==============================================================================
--- apr/apr/trunk/misc/unix/rand.c (original)
+++ apr/apr/trunk/misc/unix/rand.c Sat Nov  4 22:02:54 2017
@@ -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_ge
 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;