libgcrypt/libgcrypt-1.8.4-use-poll.patch

78 lines
2.6 KiB
Diff
Raw Normal View History

2018-11-20 15:22:10 +00:00
diff -up libgcrypt-1.8.4/random/rndlinux.c.use-poll libgcrypt-1.8.4/random/rndlinux.c
--- libgcrypt-1.8.4/random/rndlinux.c.use-poll 2018-10-26 13:50:20.000000000 +0200
+++ libgcrypt-1.8.4/random/rndlinux.c 2018-11-20 15:51:56.760669058 +0100
2013-03-20 15:38:05 +00:00
@@ -32,6 +32,7 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
+#include <poll.h>
2021-01-29 13:11:06 +00:00
#if defined(__APPLE__) && defined(__MACH__)
2021-02-17 12:01:13 +00:00
#include <Availability.h>
#ifdef __MAC_10_11
2018-11-20 15:22:10 +00:00
@@ -241,9 +242,8 @@ _gcry_rndlinux_gather_random (void (*add
2013-03-20 15:38:05 +00:00
return with something we will actually use 100ms. */
while (length)
{
- fd_set rfds;
- struct timeval tv;
int rc;
+ struct pollfd pfd;
2021-01-20 00:34:36 +00:00
/* If we have a modern operating system, we first try to use the new
* getentropy function. That call guarantees that the kernel's
2018-11-20 15:22:10 +00:00
@@ -300,36 +300,25 @@ _gcry_rndlinux_gather_random (void (*add
any_need_entropy = 1;
}
2013-03-20 15:38:05 +00:00
- /* If the system has no limit on the number of file descriptors
- and we encounter an fd which is larger than the fd_set size,
- we don't use the select at all. The select code is only used
- to emit progress messages. A better solution would be to
- fall back to poll() if available. */
-#ifdef FD_SETSIZE
- if (fd < FD_SETSIZE)
-#endif
2017-01-30 17:05:13 +00:00
+ pfd.fd = fd;
+ pfd.events = POLLIN;
+
2017-08-16 08:55:16 +00:00
+ _gcry_pre_syscall ();
+ rc = poll(&pfd, 1, delay);
+ _gcry_post_syscall ();
+ if (!rc)
2016-11-23 08:56:34 +00:00
{
2013-03-20 15:38:05 +00:00
- FD_ZERO(&rfds);
- FD_SET(fd, &rfds);
- tv.tv_sec = delay;
- tv.tv_usec = delay? 0 : 100000;
2017-08-16 08:55:16 +00:00
- _gcry_pre_syscall ();
- rc = select (fd+1, &rfds, NULL, NULL, &tv);
- _gcry_post_syscall ();
- if (!rc)
2013-03-20 15:38:05 +00:00
- {
- any_need_entropy = 1;
2013-03-20 15:38:05 +00:00
- delay = 3; /* Use 3 seconds henceforth. */
- continue;
- }
- else if( rc == -1 )
- {
2013-03-20 15:38:05 +00:00
- log_error ("select() error: %s\n", strerror(errno));
- if (!delay)
- delay = 1; /* Use 1 second if we encounter an error before
- we have ever blocked. */
- continue;
- }
2017-01-30 17:05:13 +00:00
+ any_need_entropy = 1;
+ delay = 3000; /* Use 3 seconds henceforth. */
+ continue;
+ }
+ else if( rc == -1 )
+ {
2013-03-20 15:38:05 +00:00
+ log_error ("poll() error: %s\n", strerror(errno));
+ if (!delay)
+ delay = 1000; /* Use 1 second if we encounter an error before
+ we have ever blocked. */
2013-03-20 15:38:05 +00:00
+ continue;
}
2017-08-16 08:55:16 +00:00
do