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

241384
diff -up libgcrypt-1.5.1/random/rndlinux.c.use-poll libgcrypt-1.5.1/random/rndlinux.c
241384
--- libgcrypt-1.5.1/random/rndlinux.c.use-poll	2013-03-20 15:33:26.504867356 +0100
241384
+++ libgcrypt-1.5.1/random/rndlinux.c	2013-03-20 15:37:24.999944048 +0100
241384
@@ -32,6 +32,7 @@
241384
 #include <string.h>
241384
 #include <unistd.h>
241384
 #include <fcntl.h>
241384
+#include <poll.h>
241384
 #include "types.h"
241384
 #include "g10lib.h"
241384
 #include "rand-internal.h"
241384
@@ -142,49 +143,37 @@ _gcry_rndlinux_gather_random (void (*add
241384
     }
241384
 
241384
   /* Enter the read loop.  */
241384
-  delay = 0;  /* Start with 0 seconds so that we do no block on the
241384
+  delay = 100;  /* Start with 0 seconds so that we do no block on the
241384
                  first iteration and in turn call the progress function
241384
                  before blocking.  To give the OS a better chance to
241384
                  return with something we will actually use 100ms. */
241384
   while (length)
241384
     {
241384
-      fd_set rfds;
241384
-      struct timeval tv;
241384
       int rc;
241384
+      struct pollfd pfd;
241384
 
241384
-      /* If the system has no limit on the number of file descriptors
241384
-         and we encounter an fd which is larger than the fd_set size,
241384
-         we don't use the select at all.  The select code is only used
241384
-         to emit progress messages.  A better solution would be to
241384
-         fall back to poll() if available.  */
241384
-#ifdef FD_SETSIZE
241384
-      if (fd < FD_SETSIZE)
241384
-#endif
241384
+      pfd.fd = fd;
241384
+      pfd.events = POLLIN;
241384
+
241384
+      if ( !(rc=poll(&pfd, 1, delay)) )
241384
         {
241384
-          FD_ZERO(&rfds);
241384
-          FD_SET(fd, &rfds);
241384
-          tv.tv_sec = delay;
241384
-          tv.tv_usec = delay? 0 : 100000;
241384
-          if ( !(rc=select(fd+1, &rfds, NULL, NULL, &tv)) )
241384
-            {
241384
-              if (!any_need_entropy || last_so_far != (want - length) )
241384
-                {
241384
-                  last_so_far = want - length;
241384
-                  _gcry_random_progress ("need_entropy", 'X',
241384
-                                         (int)last_so_far, (int)want);
241384
-                  any_need_entropy = 1;
241384
-                }
241384
-              delay = 3; /* Use 3 seconds henceforth.  */
241384
-              continue;
241384
-            }
241384
-          else if( rc == -1 )
241384
+          if (!any_need_entropy || last_so_far != (want - length) )
241384
             {
241384
-              log_error ("select() error: %s\n", strerror(errno));
241384
-              if (!delay)
241384
-                delay = 1; /* Use 1 second if we encounter an error before
241384
+              last_so_far = want - length;
241384
+              _gcry_random_progress ("need_entropy", 'X',
241384
+                                     (int)last_so_far, (int)want);
241384
+              any_need_entropy = 1;
241384
+	    }
241384
+          delay = 3000; /* Use 3 seconds henceforth.  */
241384
+	  continue;
241384
+	}
241384
+      else if( rc == -1 )
241384
+        {
241384
+          log_error ("poll() error: %s\n", strerror(errno));
241384
+          if (!delay)
241384
+            delay = 1000; /* Use 1 second if we encounter an error before
241384
                           we have ever blocked.  */
241384
-              continue;
241384
-            }
241384
+          continue;
241384
         }
241384
 
241384
       do