When /dev/urandom is not available, we have to use some kind of a hack
to generate a random MBR identifier. Use a better fallback that
incorporates the clock down to microsecond granularity.
Signed-off-by: H. Peter Anvin" <hpa@zytor.com>
#include <errno.h>
#include <getopt.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <time.h>
#include "nls.h"
int fd;
unsigned int v;
ssize_t rv = -1;
+ struct timeval tv;
fd = open("/dev/urandom", O_RDONLY);
if (fd >= 0) {
return v;
/* Fallback: sucks, but better than nothing */
- return (unsigned int)(getpid() + time(NULL));
+ gettimeofday(&tv, NULL);
+ return (unsigned int)(tv.tv_sec + (tv.tv_usec << 12) + getpid());
}
/* normally O_RDWR, -l option gives O_RDONLY */