zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r1718209 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/c/src/zookeeper.c
Date Sun, 06 Dec 2015 19:32:56 GMT
Author: rgs
Date: Sun Dec  6 19:32:55 2015
New Revision: 1718209

URL: http://svn.apache.org/viewvc?rev=1718209&view=rev
Log:
ZOOKEEPER-2311: assert in setup_random
(Marshall McMullen via rgs)

Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/c/src/zookeeper.c

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1718209&r1=1718208&r2=1718209&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Sun Dec  6 19:32:55 2015
@@ -8,6 +8,9 @@ BUGFIXES:
   ZOOKEEPER-2211: PurgeTxnLog does not correctly purge when snapshots and
   logs are at different locations (Arshad Mohammad via rgs)
 
+  ZOOKEEPER-2311: assert in setup_random
+  (Marshall McMullen via rgs)
+
 Release 3.4.7 - 2015-11-08
 
 Backward compatible changes:

Modified: zookeeper/branches/branch-3.4/src/c/src/zookeeper.c
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/c/src/zookeeper.c?rev=1718209&r1=1718208&r2=1718209&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/c/src/zookeeper.c (original)
+++ zookeeper/branches/branch-3.4/src/c/src/zookeeper.c Sun Dec  6 19:32:55 2015
@@ -424,8 +424,22 @@ static void setup_random()
     if (fd == -1) {
         seed = getpid();
     } else {
-        int rc = read(fd, &seed, sizeof(seed));
-        assert(rc == sizeof(seed));
+        int seed_len = 0;
+
+        /* Enter a loop to fill in seed with random data from /dev/urandom.
+         * This is done in a loop so that we can safely handle short reads
+         * which can happen due to signal interruptions.
+         */
+        while (seed_len < sizeof(seed)) {
+            /* Assert we either read something or we were interrupted due to a
+             * signal (errno == EINTR) in which case we need to retry.
+             */
+            int rc = read(fd, &seed + seed_len, sizeof(seed) - seed_len);
+            assert(rc > 0 || errno == EINTR);
+            if (rc > 0) {
+                seed_len += rc;
+            }
+        }
         close(fd);
     }
     srandom(seed);



Mime
View raw message