diff options
-rw-r--r-- | configure.in | 30 | ||||
-rw-r--r-- | misc/unix/rand.c | 9 |
2 files changed, 22 insertions, 17 deletions
diff --git a/configure.in b/configure.in index 71c4b6b48..4fc185c94 100644 --- a/configure.in +++ b/configure.in @@ -2489,25 +2489,25 @@ AC_ARG_WITH(egd, if test "$rand" != "1"; then if test "$ac_cv_func_getrandom" = yes; then - AC_MSG_RESULT(getrandom) - rand="1" + rand="getrandom" elif test "$ac_cv_have_decl_SYS_getrandom" = yes; then - AC_MSG_RESULT(SYS_getrandom) - rand="1" - fi -fi - -if test "$rand" != "1"; then - if test "$ac_cv_func_arc4random_buf" = yes; then - AC_MSG_RESULT(arc4random) - rand="1" + rand="SYS_getrandom" + elif test "$ac_cv_func_arc4random_buf" = yes; then + rand="arc4random" fi fi if test "$rand" != "1"; then AC_ARG_WITH(devrandom, [ --with-devrandom[[=DEV]] use /dev/random or compatible [[searches by default]]], - [ apr_devrandom="$withval" ], [ apr_devrandom="yes" ]) + [ apr_devrandom="$withval" ], [ apr_devrandom="no" ]) + if test "$apr_devrandom" = "no"; then + if test -z "$rand"; then + apr_devrandom="yes" + else + apr_devrandom="no" + fi + fi if test "$apr_devrandom" = "yes"; then # /dev/random on OpenBSD doesn't provide random data, so @@ -2515,7 +2515,7 @@ if test "$rand" != "1"; then for f in /dev/arandom /dev/urandom /dev/random; do if test -r $f; then apr_devrandom=$f - rand=1 + rand="1" break fi done @@ -2541,6 +2541,10 @@ if test "$rand" != "1"; then if test "$rand" = "1"; then AC_DEFINE_UNQUOTED(DEV_RANDOM, ["$apr_devrandom"], [Define to path of random device]) AC_MSG_RESULT([$apr_devrandom]) + elif test -n "$rand"; then + AC_DEFINE_UNQUOTED(SYS_RANDOM, ["$rand"], [Define system call of random]) + AC_MSG_RESULT([$rand]) + rand="1" fi fi diff --git a/misc/unix/rand.c b/misc/unix/rand.c index 5e2359901..c0567a667 100644 --- a/misc/unix/rand.c +++ b/misc/unix/rand.c @@ -43,6 +43,7 @@ #include <sys/uuid.h> #endif +#if defined(SYS_RANDOM) #if defined(HAVE_SYS_RANDOM_H) && \ defined(HAVE_GETRANDOM) @@ -60,12 +61,12 @@ #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 */ +#endif /* SYS_RANDOM */ #ifndef SHUT_RDWR #define SHUT_RDWR 2 @@ -207,12 +208,12 @@ APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char *buf, return bad_errno; } -#elif defined(USE_GETRANDOM) +#elif defined(SYS_RANDOM) && defined(USE_GETRANDOM) do { int rc; - rc = getrandom(buf, length, GRND_NONBLOCK); + rc = getrandom(buf, length, 0); if (rc == -1) { if (errno == EINTR) { continue; @@ -224,7 +225,7 @@ APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char *buf, length -= rc; } while (length > 0); -#elif defined(HAVE_ARC4RANDOM_BUF) +#elif defined(SYS_RANDOM) && defined(HAVE_ARC4RANDOM_BUF) arc4random_buf(buf, length); |