|
|
9fde57 |
diff -up libgcrypt-1.8.0/random/rndlinux.c.use-poll libgcrypt-1.8.0/random/rndlinux.c
|
|
|
9fde57 |
--- libgcrypt-1.8.0/random/rndlinux.c.use-poll 2017-06-24 13:34:29.000000000 +0200
|
|
|
9fde57 |
+++ libgcrypt-1.8.0/random/rndlinux.c 2017-08-15 15:37:37.604629377 +0200
|
|
|
9fde57 |
@@ -32,6 +32,7 @@
|
|
|
9fde57 |
#include <string.h>
|
|
|
9fde57 |
#include <unistd.h>
|
|
|
9fde57 |
#include <fcntl.h>
|
|
|
9fde57 |
+#include <poll.h>
|
|
|
9fde57 |
#if defined(__linux__) && defined(HAVE_SYSCALL)
|
|
|
9fde57 |
# include <sys/syscall.h>
|
|
|
9fde57 |
#endif
|
|
|
9fde57 |
@@ -216,9 +217,8 @@ _gcry_rndlinux_gather_random (void (*add
|
|
|
9fde57 |
return with something we will actually use 100ms. */
|
|
|
9fde57 |
while (length)
|
|
|
9fde57 |
{
|
|
|
9fde57 |
- fd_set rfds;
|
|
|
9fde57 |
- struct timeval tv;
|
|
|
9fde57 |
int rc;
|
|
|
9fde57 |
+ struct pollfd pfd;
|
|
|
9fde57 |
|
|
|
9fde57 |
/* If we have a modern Linux kernel and we want to read from the
|
|
|
9fde57 |
* the non-blocking /dev/urandom, we first try to use the new
|
|
|
9fde57 |
@@ -276,36 +276,25 @@ _gcry_rndlinux_gather_random (void (*add
|
|
|
9fde57 |
any_need_entropy = 1;
|
|
|
9fde57 |
}
|
|
|
9fde57 |
|
|
|
9fde57 |
- /* If the system has no limit on the number of file descriptors
|
|
|
9fde57 |
- and we encounter an fd which is larger than the fd_set size,
|
|
|
9fde57 |
- we don't use the select at all. The select code is only used
|
|
|
9fde57 |
- to emit progress messages. A better solution would be to
|
|
|
9fde57 |
- fall back to poll() if available. */
|
|
|
9fde57 |
-#ifdef FD_SETSIZE
|
|
|
9fde57 |
- if (fd < FD_SETSIZE)
|
|
|
9fde57 |
-#endif
|
|
|
9fde57 |
+ pfd.fd = fd;
|
|
|
9fde57 |
+ pfd.events = POLLIN;
|
|
|
9fde57 |
+
|
|
|
9fde57 |
+ _gcry_pre_syscall ();
|
|
|
9fde57 |
+ rc = poll(&pfd, 1, delay);
|
|
|
9fde57 |
+ _gcry_post_syscall ();
|
|
|
9fde57 |
+ if (!rc)
|
|
|
9fde57 |
{
|
|
|
9fde57 |
- FD_ZERO(&rfds);
|
|
|
9fde57 |
- FD_SET(fd, &rfds);
|
|
|
9fde57 |
- tv.tv_sec = delay;
|
|
|
9fde57 |
- tv.tv_usec = delay? 0 : 100000;
|
|
|
9fde57 |
- _gcry_pre_syscall ();
|
|
|
9fde57 |
- rc = select (fd+1, &rfds, NULL, NULL, &tv;;
|
|
|
9fde57 |
- _gcry_post_syscall ();
|
|
|
9fde57 |
- if (!rc)
|
|
|
9fde57 |
- {
|
|
|
9fde57 |
- any_need_entropy = 1;
|
|
|
9fde57 |
- delay = 3; /* Use 3 seconds henceforth. */
|
|
|
9fde57 |
- continue;
|
|
|
9fde57 |
- }
|
|
|
9fde57 |
- else if( rc == -1 )
|
|
|
9fde57 |
- {
|
|
|
9fde57 |
- log_error ("select() error: %s\n", strerror(errno));
|
|
|
9fde57 |
- if (!delay)
|
|
|
9fde57 |
- delay = 1; /* Use 1 second if we encounter an error before
|
|
|
9fde57 |
- we have ever blocked. */
|
|
|
9fde57 |
- continue;
|
|
|
9fde57 |
- }
|
|
|
9fde57 |
+ any_need_entropy = 1;
|
|
|
9fde57 |
+ delay = 3000; /* Use 3 seconds henceforth. */
|
|
|
9fde57 |
+ continue;
|
|
|
9fde57 |
+ }
|
|
|
9fde57 |
+ else if( rc == -1 )
|
|
|
9fde57 |
+ {
|
|
|
9fde57 |
+ log_error ("poll() error: %s\n", strerror(errno));
|
|
|
9fde57 |
+ if (!delay)
|
|
|
9fde57 |
+ delay = 1000; /* Use 1 second if we encounter an error before
|
|
|
9fde57 |
+ we have ever blocked. */
|
|
|
9fde57 |
+ continue;
|
|
|
9fde57 |
}
|
|
|
9fde57 |
|
|
|
9fde57 |
do
|