aboutsummaryrefslogtreecommitdiffstats
path: root/util-src/crand.c
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-03-02 23:03:02 +0100
committerKim Alvefur <zash@zash.se>2017-03-02 23:03:02 +0100
commit8407f360939fe103a991641b0bf3b85e87d660b9 (patch)
tree4b71bdc7622635a101579c04b2d9e0c56991df2c /util-src/crand.c
parenta11a584a59cde70ce4f0880049b9e675d8b2e223 (diff)
parentfdf81e53aa57c68f330deecf4f97cfefb05f5044 (diff)
downloadprosody-8407f360939fe103a991641b0bf3b85e87d660b9.tar.gz
prosody-8407f360939fe103a991641b0bf3b85e87d660b9.zip
Merge 0.10->trunk
Diffstat (limited to 'util-src/crand.c')
-rw-r--r--util-src/crand.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/util-src/crand.c b/util-src/crand.c
index f3fa00ea..ef9da4d2 100644
--- a/util-src/crand.c
+++ b/util-src/crand.c
@@ -19,6 +19,8 @@
*
*/
+#define _DEFAULT_SOURCE
+
#include "lualib.h"
#include "lauxlib.h"
@@ -26,21 +28,22 @@
#include <errno.h>
#if defined(WITH_GETRANDOM)
+
+#if ! __GLIBC_PREREQ(2,25)
#include <unistd.h>
#include <sys/syscall.h>
-#include <linux/random.h>
#ifndef SYS_getrandom
#error getrandom() requires Linux 3.17 or later
#endif
-/*
- * This acts like a read from /dev/urandom with the exception that it
- * *does* block if the entropy pool is not yet initialized.
- */
-int getrandom(void *buf, size_t len, int flags) {
- return syscall(SYS_getrandom, buf, len, flags);
+/* This wasn't present before glibc 2.25 */
+int getrandom(void *buf, size_t buflen, unsigned int flags) {
+ return syscall(SYS_getrandom, buf, buflen, flags);
}
+#else
+#include <sys/random.h>
+#endif
#elif defined(WITH_ARC4RANDOM)
#include <stdlib.h>
@@ -56,6 +59,10 @@ int Lrandom(lua_State *L) {
void *buf = lua_newuserdata(L, len);
#if defined(WITH_GETRANDOM)
+ /*
+ * This acts like a read from /dev/urandom with the exception that it
+ * *does* block if the entropy pool is not yet initialized.
+ */
ret = getrandom(buf, len, 0);
if(ret < 0) {