diff options
Diffstat (limited to 'src/lib/libc')
| -rw-r--r-- | src/lib/libc/stdlib/random.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/random.c b/src/lib/libc/stdlib/random.c index 2b97c5a54a..5ce7c90ee9 100644 --- a/src/lib/libc/stdlib/random.c +++ b/src/lib/libc/stdlib/random.c | |||
| @@ -32,7 +32,7 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | static char *rcsid = "$OpenBSD: random.c,v 1.8 2000/04/04 13:38:24 millert Exp $"; | 35 | static char *rcsid = "$OpenBSD: random.c,v 1.9 2000/04/04 14:27:00 millert Exp $"; |
| 36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 37 | 37 | ||
| 38 | #include <sys/types.h> | 38 | #include <sys/types.h> |
| @@ -245,18 +245,20 @@ srandomdev() | |||
| 245 | else | 245 | else |
| 246 | len = rand_deg * sizeof(state[0]); | 246 | len = rand_deg * sizeof(state[0]); |
| 247 | 247 | ||
| 248 | if ((fd = open("/dev/arandom", O_RDONLY, 0)) == -1 || | 248 | if ((fd = open("/dev/arandom", O_RDONLY, 0)) != -1 && |
| 249 | read(fd, (void *) state, len) != (ssize_t) len) { | 249 | read(fd, (void *) state, len) == (ssize_t) len) { |
| 250 | close(fd); | ||
| 251 | } else { | ||
| 250 | struct timeval tv; | 252 | struct timeval tv; |
| 251 | u_int junk; | 253 | u_int junk; |
| 252 | 254 | ||
| 253 | /* XXX - this could be better */ | 255 | /* XXX - this could be better */ |
| 254 | gettimeofday(&tv, NULL); | 256 | gettimeofday(&tv, NULL); |
| 255 | srandom(getpid() ^ tv.tv_sec ^ tv.tv_usec ^ junk); | 257 | srandom(getpid() ^ tv.tv_sec ^ tv.tv_usec ^ junk); |
| 258 | if (fd != -1) | ||
| 259 | close(fd); | ||
| 256 | return; | 260 | return; |
| 257 | } | 261 | } |
| 258 | if (fd != -1) | ||
| 259 | close(fd); | ||
| 260 | 262 | ||
| 261 | if (rand_type != TYPE_0) { | 263 | if (rand_type != TYPE_0) { |
| 262 | fptr = &state[rand_sep]; | 264 | fptr = &state[rand_sep]; |
