Commit 01d04b52 authored by Tollef Fog Heen's avatar Tollef Fog Heen

Fall back to using current time if urandom is not available

parent 6645f2ad
......@@ -35,6 +35,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/stat.h>
......@@ -47,8 +48,12 @@ seed_random(void)
unsigned seed;
fd = open("/dev/urandom", O_RDONLY);
if (fd == -1)
return (1);
if (fd == -1) {
/* urandom not available, fall back to something
* weaker */
srandom(time(NULL));
return (0);
}
if (read(fd, &seed, sizeof seed) != sizeof seed)
return (1);
(void)close(fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment