In init_rand avoid reading from /dev/urandom on NetBSD/FreeBSD

Use the KERN_ARND sysctl instead.
This commit is contained in:
nia 2020-05-01 17:23:27 +01:00
parent 14a954f350
commit 74ad315360

View File

@ -1462,6 +1462,14 @@ static void init_rand() {
unsigned seed;
memcpy(&seed, ptr_random, sizeof(seed));
srand(seed);
#elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
unsigned seed;
size_t len = sizeof(seed);
int mib[2] = { CTL_KERN, KERN_ARND };
if (sysctl(mib, 2, &seed, &len, NULL, 0) != 0) {
zig_panic("unable to query random data from sysctl");
}
srand(seed);
#else
int fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC);
if (fd == -1) {