diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-10-13 20:43:52 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-10-17 19:26:07 +0200 |
commit | 113bf1d2e83d07f30d3bf58699eff03e9518df6d (patch) | |
tree | 79893a055bdb75c933bb2c6763a3eac6bd058604 /src/tests/qemu | |
parent | 94fbd80d7ca8f1451ad98fe9789f2c5b6803992d (diff) |
qemu: open /dev/console if we're started early
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/tests/qemu')
-rw-r--r-- | src/tests/qemu/init.c | 22 |
1 files changed, 19 insertions, 3 deletions
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); |