This simplifies the code by avoiding an allocation and free. Signed-off-by: Alyssa Ross <hi@alyssa.is> --- release/checks/integration/networking.c | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/release/checks/integration/networking.c b/release/checks/integration/networking.c index efc7b44..1e5983f 100644 --- a/release/checks/integration/networking.c +++ b/release/checks/integration/networking.c @@ -184,14 +184,13 @@ struct config { } drives; }; -static FILE *start_qemu(const char *tmp_dir, struct config c) +static FILE *start_qemu(struct config c) { FILE *console; struct utsname u; int console_listener, console_conn; char *arch, *args[] = { (char *)c.run_qemu, - "-serial", nullptr, "-drive", nullptr, "-drive", nullptr, "-drive", nullptr, @@ -207,6 +206,7 @@ static FILE *start_qemu(const char *tmp_dir, struct config c) "-monitor", "vc", "-vga", "none", "-smbios", "type=11,value=io.systemd.stub.kernel-cmdline-extra=console=ttyS0", + "-serial", "unix:console", nullptr, }; @@ -217,12 +217,7 @@ static FILE *start_qemu(const char *tmp_dir, struct config c) if (strcmp(arch, "x86_64")) args[sizeof args / sizeof *args - 3] = nullptr; - if (asprintf(&args[2], "unix:%s/console", tmp_dir) == -1) { - perror("asprintf"); - exit(EXIT_FAILURE); - } - - console_listener = setup_unix(args[2] + strlen("unix:")); + console_listener = setup_unix("console"); switch (fork()) { case -1: @@ -234,9 +229,9 @@ static FILE *start_qemu(const char *tmp_dir, struct config c) exit(EXIT_FAILURE); } - if (asprintf(&args[4], "file=%s,format=raw,if=pflash,readonly=true", c.drives.efi) == -1 || - asprintf(&args[6], "file=%s,format=raw,if=virtio,readonly=true", c.drives.img) == -1 || - asprintf(&args[8], "file=%s,format=raw,if=virtio,readonly=true", c.drives.user_data) == -1) { + if (asprintf(&args[2], "file=%s,format=raw,if=pflash,readonly=true", c.drives.efi) == -1 || + asprintf(&args[4], "file=%s,format=raw,if=virtio,readonly=true", c.drives.img) == -1 || + asprintf(&args[6], "file=%s,format=raw,if=virtio,readonly=true", c.drives.user_data) == -1) { perror("asprintf"); exit(EXIT_FAILURE); } @@ -246,8 +241,6 @@ static FILE *start_qemu(const char *tmp_dir, struct config c) exit(EXIT_FAILURE); } - free(args[2]); - if ((console_conn = accept(console_listener, nullptr, nullptr)) == -1) { perror("accept"); exit(EXIT_FAILURE); @@ -323,9 +316,14 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + if (chdir(make_tmp_dir()) == -1) { + perror("chdir"); + exit(EXIT_FAILURE); + } + int server = setup_server(); - FILE *console = start_qemu(make_tmp_dir(), c); + FILE *console = start_qemu(c); if (fputs("set -euxo pipefail\n" "mkdir /run/mnt\n" -- 2.49.0