1c953f2
diff -up libgcrypt-1.7.6/random/rndlinux.c.use-poll libgcrypt-1.7.6/random/rndlinux.c
1c953f2
--- libgcrypt-1.7.6/random/rndlinux.c.use-poll	2017-01-30 14:20:13.665662981 +0100
1c953f2
+++ libgcrypt-1.7.6/random/rndlinux.c	2017-01-30 14:27:45.957027214 +0100
1aafe14
@@ -32,6 +32,7 @@
1aafe14
 #include <string.h>
1aafe14
 #include <unistd.h>
1aafe14
 #include <fcntl.h>
1aafe14
+#include <poll.h>
2c8c022
 #if defined(__linux__) && defined(HAVE_SYSCALL)
2c8c022
 # include <sys/syscall.h>
2c8c022
 #endif
1c953f2
@@ -211,9 +212,8 @@ _gcry_rndlinux_gather_random (void (*add
1aafe14
                  return with something we will actually use 100ms. */
1aafe14
   while (length)
1aafe14
     {
1aafe14
-      fd_set rfds;
1aafe14
-      struct timeval tv;
1aafe14
       int rc;
1aafe14
+      struct pollfd pfd;
247b211
 
1c953f2
       /* If we have a modern Linux kernel and we want to read from the
1c953f2
        * the non-blocking /dev/urandom, we first try to use the new
1c953f2
@@ -269,33 +269,22 @@ _gcry_rndlinux_gather_random (void (*add
247b211
           any_need_entropy = 1;
247b211
         }
1aafe14
 
1aafe14
-      /* If the system has no limit on the number of file descriptors
1aafe14
-         and we encounter an fd which is larger than the fd_set size,
1aafe14
-         we don't use the select at all.  The select code is only used
1aafe14
-         to emit progress messages.  A better solution would be to
1aafe14
-         fall back to poll() if available.  */
1aafe14
-#ifdef FD_SETSIZE
1aafe14
-      if (fd < FD_SETSIZE)
1aafe14
-#endif
1c953f2
+      pfd.fd = fd;
1c953f2
+      pfd.events = POLLIN;
1c953f2
+
2c8c022
+      if ( !(rc=poll(&pfd, 1, delay)) )
2c8c022
         {
1aafe14
-          FD_ZERO(&rfds);
1aafe14
-          FD_SET(fd, &rfds);
1aafe14
-          tv.tv_sec = delay;
1aafe14
-          tv.tv_usec = delay? 0 : 100000;
1aafe14
-          if ( !(rc=select(fd+1, &rfds, NULL, NULL, &tv)) )
1aafe14
-            {
247b211
-              any_need_entropy = 1;
1aafe14
-              delay = 3; /* Use 3 seconds henceforth.  */
1aafe14
-              continue;
1aafe14
-            }
1aafe14
-          else if( rc == -1 )
247b211
-            {
1aafe14
-              log_error ("select() error: %s\n", strerror(errno));
1aafe14
-              if (!delay)
1aafe14
-                delay = 1; /* Use 1 second if we encounter an error before
247b211
-                              we have ever blocked.  */
247b211
-              continue;
247b211
-            }
1c953f2
+          any_need_entropy = 1;
1c953f2
+          delay = 3000; /* Use 3 seconds henceforth.  */
1c953f2
+          continue;
1c953f2
+        }
1c953f2
+        else if( rc == -1 )
1c953f2
+        {
1aafe14
+          log_error ("poll() error: %s\n", strerror(errno));
1aafe14
+          if (!delay)
1aafe14
+            delay = 1000; /* Use 1 second if we encounter an error before
247b211
+                          we have ever blocked.  */
1aafe14
+          continue;
1aafe14
         }
1aafe14
 
1c953f2
       /* Read from the device.  */