From: Daan De Meyer Date: Thu, 28 Mar 2024 10:56:15 +0000 (+0100) Subject: Rework spawn() process termination slightly X-Git-Tag: v23~50^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50c342d8ae0fc376af388f5a50953db43da9dc78;p=thirdparty%2Fmkosi.git Rework spawn() process termination slightly --- diff --git a/mkosi/qemu.py b/mkosi/qemu.py index c229ed34a..db29d136f 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -274,11 +274,8 @@ def start_swtpm(config: Config) -> Iterator[Path]: pass_fds=(sock.fileno(),), sandbox=config.sandbox(mounts=[Mount(state, state)]), ) as proc: - try: - yield path - finally: - proc.terminate() - proc.wait() + yield path + proc.terminate() def find_virtiofsd(*, tools: Path = Path("/")) -> Optional[Path]: @@ -349,11 +346,8 @@ def start_virtiofsd(config: Config, directory: Path, *, uidmap: bool) -> Iterato options=["--uid", "0", "--gid", "0", "--cap-add", "all"], ), ) as proc: - try: - yield path - finally: - proc.terminate() - proc.wait() + yield path + proc.terminate() @contextlib.contextmanager @@ -933,7 +927,6 @@ def run_qemu(args: Args, config: Config) -> None: for fd in qemu_device_fds.values(): os.close(fd) - qemu.wait() if status := int(notifications.get("EXIT_STATUS", 0)): raise subprocess.CalledProcessError(status, cmdline) diff --git a/mkosi/run.py b/mkosi/run.py index 327967765..548ca52e2 100644 --- a/mkosi/run.py +++ b/mkosi/run.py @@ -304,7 +304,12 @@ def spawn( env=env, preexec_fn=preexec, ) as proc: - yield proc + try: + yield proc + except BaseException: + proc.terminate() + finally: + proc.wait() except FileNotFoundError as e: die(f"{e.filename} not found.") except subprocess.CalledProcessError as e: