summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-25 12:03:50 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-25 12:03:50 (GMT)
commite02186f5263ebecea941cf8554206c6ac5b04ab3 (patch)
tree5791735dda873dd3051f11ec5225c28cb5f9f5fe /random.c
parent6e54a6df2291715bedaac454c34880b242848d78 (diff)
random.c: get rid of blocking
* random.c (fill_random_bytes_syscall): get rid of blocking when no entropy is available. based on the patch by mame in [ruby-core:70114]. [Bug #11395] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r--random.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/random.c b/random.c
index 6452456..9f39dc2 100644
--- a/random.c
+++ b/random.c
@@ -516,6 +516,12 @@ fill_random_bytes_syscall(void *seed, size_t size)
return 0;
}
#elif defined __linux__ && defined SYS_getrandom
+#include <linux/random.h>
+
+# ifndef GRND_NONBLOCK
+# define GRND_NONBLOCK 0x0001 /* not defined in musl libc */
+# endif
+
static int
fill_random_bytes_syscall(void *seed, size_t size)
{
@@ -523,7 +529,7 @@ fill_random_bytes_syscall(void *seed, size_t size)
if (try_syscall) {
long ret;
errno = 0;
- ret = syscall(SYS_getrandom, seed, size, 0);
+ ret = syscall(SYS_getrandom, seed, size, GRND_NONBLOCK);
if (errno == ENOSYS) {
try_syscall = 0;
return -1;