libgcrypt/libgcrypt-1.5.0-use-poll.patch

58 lines
2.0 KiB
Diff

diff -up libgcrypt-1.5.0/random/rndlinux.c.use-poll libgcrypt-1.5.0/random/rndlinux.c
--- libgcrypt-1.5.0/random/rndlinux.c.use-poll 2012-04-05 15:37:52.000000000 +0200
+++ libgcrypt-1.5.0/random/rndlinux.c 2013-03-05 14:15:29.735709032 +0100
@@ -32,6 +32,7 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
+#include <poll.h>
#include "types.h"
#include "g10lib.h"
#include "rand-internal.h"
@@ -142,21 +143,19 @@ _gcry_rndlinux_gather_random (void (*add
}
/* Enter the read loop. */
- delay = 0; /* Start with 0 seconds so that we do no block on the
+ delay = 100; /* Start with 0 seconds so that we do no block on the
first iteration and in turn call the progress function
before blocking. To give the OS a better chance to
return with something we will actually use 100ms. */
while (length)
{
- fd_set rfds;
- struct timeval tv;
int rc;
+ struct pollfd pfd;
- FD_ZERO(&rfds);
- FD_SET(fd, &rfds);
- tv.tv_sec = delay;
- tv.tv_usec = delay? 0 : 100000;
- if ( !(rc=select(fd+1, &rfds, NULL, NULL, &tv)) )
+ pfd.fd = fd;
+ pfd.events = POLLIN;
+
+ if ( !(rc=poll(&pfd, 1, delay)) )
{
if (!any_need_entropy || last_so_far != (want - length) )
{
@@ -165,14 +164,14 @@ _gcry_rndlinux_gather_random (void (*add
(int)last_so_far, (int)want);
any_need_entropy = 1;
}
- delay = 3; /* Use 3 seconds henceforth. */
+ delay = 3000; /* Use 3 seconds henceforth. */
continue;
}
else if( rc == -1 )
{
- log_error ("select() error: %s\n", strerror(errno));
+ log_error ("poll() error: %s\n", strerror(errno));
if (!delay)
- delay = 1; /* Use 1 second if we encounter an error before
+ delay = 1000; /* Use 1 second if we encounter an error before
we have ever blocked. */
continue;
}