diff options
author | Yann Ylavic <ylavic@apache.org> | 2017-11-04 22:02:54 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2017-11-04 22:02:54 +0000 |
commit | 543cc5474cf20dd42f002aa42932b566ec559a61 (patch) | |
tree | eae10d788079ac0d40df83cad63be4056a6cc7a8 /misc | |
parent | 496a47bfb610cf5bf58ffa8181102f7578cbd054 (diff) | |
download | apr-543cc5474cf20dd42f002aa42932b566ec559a61.tar.gz |
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).
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1814326 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc')
-rw-r--r-- | misc/unix/rand.c | 23 |
1 files changed, 21 insertions, 2 deletions
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; |