Whamcloud - gitweb
gen_uuid.c (get_random_bytes): Don't spin forever if read()
authorTheodore Ts'o <tytso@mit.edu>
Thu, 31 Oct 2002 20:17:16 +0000 (15:17 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 31 Oct 2002 20:17:16 +0000 (15:17 -0500)
returns EINTR or EAGAIN, so that when /dev/random is
opened O_NONBLOCK, we don't end up spinning forever.

lib/uuid/ChangeLog
lib/uuid/gen_uuid.c

index dab24df..3e7da5c 100644 (file)
@@ -1,3 +1,9 @@
+2002-10-31  Theodore Ts'o  <tytso@mit.edu>
+
+       * gen_uuid.c (get_random_bytes): Don't spin forever if read()
+               returns EINTR or EAGAIN, so that when /dev/random is
+               opened O_NONBLOCK, we don't end up spinning forever.
+
 2001-09-24  Theodore Tso  <tytso@mit.edu>
 
        * Release of E2fsprogs 1.29
index 1f72439..5ebc673 100644 (file)
@@ -81,11 +81,8 @@ static void get_random_bytes(void *buf, int nbytes)
        if (fd >= 0) {
                while (nbytes > 0) {
                        i = read(fd, cp, nbytes);
-                       if ((i < 0) &&
-                           ((errno == EINTR) || (errno == EAGAIN)))
-                               continue;
                        if (i <= 0) {
-                               if (lose_counter++ == 8)
+                               if (lose_counter++ > 16)
                                        break;
                                continue;
                        }