1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2015-07-25 12:03:50 +00:00
parent 6e54a6df22
commit e02186f526
2 changed files with 13 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Sat Jul 25 21:03:45 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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]
Sat Jul 25 11:05:31 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (str_replace_shared_without_enc): fill the terminator

View file

@ -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;