Blame SOURCES/libgcrypt-1.8.4-use-poll.patch

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