74 lines
1.8 KiB
Diff
74 lines
1.8 KiB
Diff
|
--- openssl-0.9.8a/crypto/rand/rand_unix.c.use-poll 2005-08-29 01:20:48.000000000 +0200
|
||
|
+++ openssl-0.9.8a/crypto/rand/rand_unix.c 2005-11-08 01:28:35.000000000 +0100
|
||
|
@@ -125,6 +125,7 @@
|
||
|
#include <fcntl.h>
|
||
|
#include <unistd.h>
|
||
|
#include <time.h>
|
||
|
+#include <sys/poll.h>
|
||
|
|
||
|
#ifdef __OpenBSD__
|
||
|
int RAND_poll(void)
|
||
|
@@ -157,6 +158,7 @@
|
||
|
struct stat randomstats[sizeof(randomfiles)/sizeof(randomfiles[0])];
|
||
|
int fd;
|
||
|
size_t i;
|
||
|
+ struct pollfd pfd;
|
||
|
#endif
|
||
|
#ifdef DEVRANDOM_EGD
|
||
|
static const char *egdsockets[] = { DEVRANDOM_EGD, NULL };
|
||
|
@@ -184,11 +186,10 @@
|
||
|
#endif
|
||
|
)) >= 0)
|
||
|
{
|
||
|
- struct timeval t = { 0, 10*1000 }; /* Spend 10ms on
|
||
|
+ int t = 10; /* Spend 10ms on
|
||
|
each file. */
|
||
|
int r;
|
||
|
size_t j;
|
||
|
- fd_set fset;
|
||
|
struct stat *st=&randomstats[i];
|
||
|
|
||
|
/* Avoid using same input... Used to be O_NOFOLLOW
|
||
|
@@ -204,30 +205,25 @@
|
||
|
|
||
|
do
|
||
|
{
|
||
|
- FD_ZERO(&fset);
|
||
|
- FD_SET(fd, &fset);
|
||
|
- r = -1;
|
||
|
-
|
||
|
- if (select(fd+1,&fset,NULL,NULL,&t) < 0)
|
||
|
- t.tv_usec=0;
|
||
|
- else if (FD_ISSET(fd, &fset))
|
||
|
+ pfd.fd = fd;
|
||
|
+ pfd.events = POLLIN;
|
||
|
+ pfd.revents = 0;
|
||
|
+
|
||
|
+ if ((r=poll(&pfd,1,t)) == 0)
|
||
|
+ t = 0;
|
||
|
+ else if (r > 0 && (pfd.revents & POLLIN))
|
||
|
{
|
||
|
r=read(fd,(unsigned char *)tmpbuf+n,
|
||
|
ENTROPY_NEEDED-n);
|
||
|
if (r > 0)
|
||
|
n += r;
|
||
|
}
|
||
|
-
|
||
|
- /* Some Unixen will update t, some
|
||
|
- won't. For those who won't, give
|
||
|
- up here, otherwise, we will do
|
||
|
- this once again for the remaining
|
||
|
- time. */
|
||
|
- if (t.tv_usec == 10*1000)
|
||
|
- t.tv_usec=0;
|
||
|
+ /* we don't know how big part of the timeout elapsed
|
||
|
+ wait half the original timeout next time */
|
||
|
+ t >>= 1;
|
||
|
}
|
||
|
while ((r > 0 || (errno == EINTR || errno == EAGAIN))
|
||
|
- && t.tv_usec != 0 && n < ENTROPY_NEEDED);
|
||
|
+ && t != 0 && n < ENTROPY_NEEDED);
|
||
|
|
||
|
close(fd);
|
||
|
}
|