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