From 5022a7e3f8aad07f1e2b543827830f1f18ca318d Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 1 May 2020 10:38:26 +0200 Subject: 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 --- src/tests/qemu/init.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') 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 #include #include +#include #include #include #include @@ -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)"); } -- cgit v1.2.3