[前][次][番号順一覧][スレッド一覧]

ruby-changes:39293

From: nobu <ko1@a...>
Date: Sat, 25 Jul 2015 21:04:17 +0900 (JST)
Subject: [ruby-changes:39293] nobu:r51374 (trunk): random.c: get rid of blocking

nobu	2015-07-25 21:03:50 +0900 (Sat, 25 Jul 2015)

  New Revision: 51374

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51374

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/random.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51373)
+++ ChangeLog	(revision 51374)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jul 25 21:03:45 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* string.c (str_replace_shared_without_enc): fill the terminator
Index: random.c
===================================================================
--- random.c	(revision 51373)
+++ random.c	(revision 51374)
@@ -516,6 +516,12 @@ fill_random_bytes_syscall(void *seed, si https://github.com/ruby/ruby/blob/trunk/random.c#L516
     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, si https://github.com/ruby/ruby/blob/trunk/random.c#L529
     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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]