apr/apr-use-getrandom.patch

26 lines
643 B
Diff
Raw Normal View History

--- apr-1.5.1.orig/misc/unix/rand.c
+++ apr-1.5.1/misc/unix/rand.c
@@ -43,6 +43,9 @@
#include <sys/uuid.h>
#endif
+#include <sys/syscall.h>
+#include <linux/random.h>
+
#ifndef SHUT_RDWR
#define SHUT_RDWR 2
#endif
@@ -89,6 +92,12 @@ APR_DECLARE(apr_status_t) apr_generate_r
{
#ifdef DEV_RANDOM
+#ifdef SYS_getrandom
+ int r = TEMP_FAILURE_RETRY(syscall(SYS_getrandom, buf, length, GRND_NONBLOCK));
+ if(r != -1 && r == length)
+ return APR_SUCCESS;
+ /* If this fails for whatever reason..fallback to the old ways.. */
+#endif
int fd = -1;
/* On BSD/OS 4.1, /dev/random gives out 8 bytes at a time, then