From f32107e3de0b4f6a1744b641f16679eda3062e0b Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 13 Oct 2017 20:43:52 +0200 Subject: qemu: open /dev/console if we're started early --- src/tests/qemu/init.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/tests') diff --git a/src/tests/qemu/init.c b/src/tests/qemu/init.c index ecbbf75..e8d3de7 100644 --- a/src/tests/qemu/init.c +++ b/src/tests/qemu/init.c @@ -199,13 +199,29 @@ static bool linux_4_8_or_higher(const struct utsname *utsname) return KERNEL_VERSION(maj, min, rel) >= KERNEL_VERSION(4, 8, 0); } +static void ensure_console(void) +{ + for (unsigned int i = 0; i < 1000; ++i) { + int fd = open("/dev/console", O_RDWR); + if (fd < 0) { + usleep(50000); + continue; + } + dup2(fd, 0); + dup2(fd, 1); + dup2(fd, 2); + close(fd); + if (write(1, "\0\0\0\0\n", 5) == 5) + return; + } + panic("Unable to open console device"); +} + int main(int argc, char *argv[]) { struct utsname utsname; - if (write(1, "\0\0\0\0\n", 5) < 0) - reboot(RB_AUTOBOOT); - + ensure_console(); if (uname(&utsname) < 0) panic("uname"); print_banner(&utsname); -- cgit v1.2.3-59-g8ed1b