|
|
150a03 |
diff -up libgcrypt-1.8.4/random/rndlinux.c.use-poll libgcrypt-1.8.4/random/rndlinux.c
|
|
|
150a03 |
--- libgcrypt-1.8.4/random/rndlinux.c.use-poll 2018-10-26 13:50:20.000000000 +0200
|
|
|
150a03 |
+++ libgcrypt-1.8.4/random/rndlinux.c 2018-11-20 15:51:56.760669058 +0100
|
|
|
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
|
|
|
150a03 |
@@ -241,9 +242,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 |
|
|
|
150a03 |
/* If we have a modern Linux kernel, we first try to use the new
|
|
|
150a03 |
* getrandom syscall. That call guarantees that the kernel's
|
|
|
150a03 |
@@ -300,36 +300,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
|