]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Rework spawn() process termination slightly
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 28 Mar 2024 10:56:15 +0000 (11:56 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 28 Mar 2024 11:44:51 +0000 (12:44 +0100)
mkosi/qemu.py
mkosi/run.py

index c229ed34ad97c5e6c73dff723963b1518ff622f3..db29d136f7da8aee43b6d8c7f475524ff8f06d52 100644 (file)
@@ -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)
index 32796776568fdadc8b5d4068cabd5b85ed4bb1cf..548ca52e2c01c74db86f831a3eda4804f1d52696 100644 (file)
@@ -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: