aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-05-01 10:38:26 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2020-05-03 20:08:54 -0600
commit5022a7e3f8aad07f1e2b543827830f1f18ca318d (patch)
treea591e3550149fb74667df1d5917a669d531ae2f1
parente21f8816ec23e6a01529a05215a45d713d5a55b4 (diff)
downloadwireguard-linux-compat-5022a7e3f8aad07f1e2b543827830f1f18ca318d.tar.gz
qemu: loop entropy adding until getrandom doesn't block
Before the 256 was just a guess, which was made wrong by qemu 5.0, so instead actually query whether or not we're all set. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--src/tests/qemu/init.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/tests/qemu/init.c b/src/tests/qemu/init.c
index 90bc981..3e2a237 100644
--- a/src/tests/qemu/init.c
+++ b/src/tests/qemu/init.c
@@ -18,6 +18,7 @@
#include <sys/types.h>
#include <sys/io.h>
#include <sys/ioctl.h>
+#include <sys/random.h>
#include <sys/reboot.h>
#include <sys/utsname.h>
#include <sys/sendfile.h>
@@ -73,7 +74,9 @@ static void seed_rng(void)
fd = open("/dev/urandom", O_WRONLY);
if (fd < 0)
panic("open(urandom)");
- for (int i = 0; i < 256; ++i) {
+ for (;;) {
+ if (getrandom(entropy.buffer, sizeof(entropy.buffer), GRND_NONBLOCK) != -1 || errno != EAGAIN)
+ break;
if (ioctl(fd, RNDADDENTROPY, &entropy) < 0)
panic("ioctl(urandom)");
}