5bcc82
diff -up libgcrypt-1.8.4/random/rndlinux.c.use-poll libgcrypt-1.8.4/random/rndlinux.c
5bcc82
--- libgcrypt-1.8.4/random/rndlinux.c.use-poll	2018-10-26 13:50:20.000000000 +0200
5bcc82
+++ libgcrypt-1.8.4/random/rndlinux.c	2018-11-20 15:51:56.760669058 +0100
5bcc82
@@ -32,6 +32,7 @@
5bcc82
 #include <string.h>
5bcc82
 #include <unistd.h>
5bcc82
 #include <fcntl.h>
5bcc82
+#include <poll.h>
5bcc82
 #if defined(__linux__) && defined(HAVE_SYSCALL)
5bcc82
 # include <sys/syscall.h>
5bcc82
 #endif
5bcc82
@@ -241,9 +242,8 @@ _gcry_rndlinux_gather_random (void (*add
5bcc82
                  return with something we will actually use 100ms. */
5bcc82
   while (length)
5bcc82
     {
5bcc82
-      fd_set rfds;
5bcc82
-      struct timeval tv;
5bcc82
       int rc;
5bcc82
+      struct pollfd pfd;
5bcc82
 
5bcc82
       /* If we have a modern Linux kernel, we first try to use the new
5bcc82
        * getrandom syscall.  That call guarantees that the kernel's
5bcc82
@@ -300,36 +300,25 @@ _gcry_rndlinux_gather_random (void (*add
5bcc82
           any_need_entropy = 1;
5bcc82
         }
5bcc82
 
5bcc82
-      /* If the system has no limit on the number of file descriptors
5bcc82
-         and we encounter an fd which is larger than the fd_set size,
5bcc82
-         we don't use the select at all.  The select code is only used
5bcc82
-         to emit progress messages.  A better solution would be to
5bcc82
-         fall back to poll() if available.  */
5bcc82
-#ifdef FD_SETSIZE
5bcc82
-      if (fd < FD_SETSIZE)
5bcc82
-#endif
5bcc82
+      pfd.fd = fd;
5bcc82
+      pfd.events = POLLIN;
5bcc82
+
5bcc82
+      _gcry_pre_syscall ();
5bcc82
+      rc = poll(&pfd, 1, delay);
5bcc82
+      _gcry_post_syscall ();
5bcc82
+      if (!rc)
5bcc82
         {
5bcc82
-          FD_ZERO(&rfds);
5bcc82
-          FD_SET(fd, &rfds);
5bcc82
-          tv.tv_sec = delay;
5bcc82
-          tv.tv_usec = delay? 0 : 100000;
5bcc82
-          _gcry_pre_syscall ();
5bcc82
-          rc = select (fd+1, &rfds, NULL, NULL, &tv;;
5bcc82
-          _gcry_post_syscall ();
5bcc82
-          if (!rc)
5bcc82
-            {
5bcc82
-              any_need_entropy = 1;
5bcc82
-              delay = 3; /* Use 3 seconds henceforth.  */
5bcc82
-              continue;
5bcc82
-            }
5bcc82
-          else if( rc == -1 )
5bcc82
-            {
5bcc82
-              log_error ("select() error: %s\n", strerror(errno));
5bcc82
-              if (!delay)
5bcc82
-                delay = 1; /* Use 1 second if we encounter an error before
5bcc82
-                              we have ever blocked.  */
5bcc82
-              continue;
5bcc82
-            }
5bcc82
+          any_need_entropy = 1;
5bcc82
+          delay = 3000; /* Use 3 seconds henceforth.  */
5bcc82
+          continue;
5bcc82
+        }
5bcc82
+        else if( rc == -1 )
5bcc82
+        {
5bcc82
+          log_error ("poll() error: %s\n", strerror(errno));
5bcc82
+          if (!delay)
5bcc82
+            delay = 1000; /* Use 1 second if we encounter an error before
5bcc82
+                          we have ever blocked.  */
5bcc82
+          continue;
5bcc82
         }
5bcc82
 
5bcc82
       do