aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tests
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-10-13 20:43:52 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-10-17 19:26:07 +0200
commitf32107e3de0b4f6a1744b641f16679eda3062e0b (patch)
tree13c598a3aecc5c454b6f14a9aeeda42016c1737c /src/tests
parentqemu: simplify shutdown (diff)
downloadwireguard-monolithic-historical-f32107e3de0b4f6a1744b641f16679eda3062e0b.tar.xz
wireguard-monolithic-historical-f32107e3de0b4f6a1744b641f16679eda3062e0b.zip
qemu: open /dev/console if we're started early
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/qemu/init.c22
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);