]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Introduce success_exit_status argument for run() and spawn()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 13 Apr 2024 08:45:48 +0000 (10:45 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 13 Apr 2024 10:13:36 +0000 (12:13 +0200)
mkosi/__init__.py
mkosi/run.py

index 9495bd950c96cdbb8a6d85424add0ed3249fcf84..edae1bc5581a78d74e203ef4f54123d944870674 100644 (file)
@@ -64,7 +64,6 @@ from mkosi.qemu import KernelType, copy_ephemeral, run_qemu, run_ssh, start_jour
 from mkosi.run import (
     find_binary,
     fork_and_wait,
-    log_process_failure,
     run,
 )
 from mkosi.sandbox import Mount, chroot_cmd, finalize_crypto_mounts, finalize_passwd_mounts
@@ -2822,36 +2821,29 @@ def run_tmpfiles(context: Context) -> None:
         return
 
     with complete_step("Generating volatile files"):
-        cmdline = [
-            "systemd-tmpfiles",
-            "--root=/buildroot",
-            "--boot",
-            "--create",
-            "--remove",
-            # Exclude APIVFS and temporary files directories.
-            *(f"--exclude-prefix={d}" for d in ("/tmp", "/var/tmp", "/run", "/proc", "/sys", "/dev")),
-        ]
-
-        sandbox = context.sandbox(
-            mounts=[
-                Mount(context.root, "/buildroot"),
-                # systemd uses acl.h to parse ACLs in tmpfiles snippets which uses the host's passwd so we have to
-                # mount the image's passwd over it to make ACL parsing work.
-                *finalize_passwd_mounts(context.root)
+        run(
+            [
+                "systemd-tmpfiles",
+                "--root=/buildroot",
+                "--boot",
+                "--create",
+                "--remove",
+                # Exclude APIVFS and temporary files directories.
+                *(f"--exclude-prefix={d}" for d in ("/tmp", "/var/tmp", "/run", "/proc", "/sys", "/dev")),
             ],
-        )
-
-        result = run(
-            cmdline,
-            sandbox=sandbox,
             env={"SYSTEMD_TMPFILES_FORCE_SUBVOL": "0"},
-            check=False,
+            # systemd-tmpfiles can exit with DATAERR or CANTCREAT in some cases which are handled as success by the
+            # systemd-tmpfiles service so we handle those as success as well.
+            success_exit_status=(0, 65, 73),
+            sandbox=context.sandbox(
+                mounts=[
+                    Mount(context.root, "/buildroot"),
+                    # systemd uses acl.h to parse ACLs in tmpfiles snippets which uses the host's passwd so we have to
+                    # mount the image's passwd over it to make ACL parsing work.
+                    *finalize_passwd_mounts(context.root)
+                ],
+            ),
         )
-        # systemd-tmpfiles can exit with DATAERR or CANTCREAT in some cases which are handled as success by the
-        # systemd-tmpfiles service so we handle those as success as well.
-        if result.returncode not in (0, 65, 73):
-            log_process_failure([str(s) for s in sandbox], cmdline, result.returncode)
-            raise subprocess.CalledProcessError(result.returncode, cmdline)
 
 
 def run_preset(context: Context) -> None:
index 3eef72ab5a7f399fe7160c77504dd1312b29583b..ea2b9a0e0e7b287a830e241560ace88395e1993f 100644 (file)
@@ -135,6 +135,7 @@ def run(
     cwd: Optional[Path] = None,
     log: bool = True,
     preexec_fn: Optional[Callable[[], None]] = None,
+    success_exit_status: Sequence[int] = (0,),
     sandbox: Sequence[PathString] = (),
     foreground: bool = True,
 ) -> CompletedProcess:
@@ -154,6 +155,7 @@ def run(
         cwd=cwd,
         log=log,
         preexec_fn=preexec_fn,
+        success_exit_status=success_exit_status,
         sandbox=sandbox,
         foreground=foreground,
     ) as process:
@@ -177,6 +179,7 @@ def spawn(
     log: bool = True,
     foreground: bool = False,
     preexec_fn: Optional[Callable[[], None]] = None,
+    success_exit_status: Sequence[int] = (0,),
     sandbox: Sequence[PathString] = (),
 ) -> Iterator[Popen]:
     assert sorted(set(pass_fds)) == list(pass_fds)
@@ -289,7 +292,7 @@ def spawn(
             finally:
                 returncode = proc.wait()
 
-            if check and returncode:
+            if check and returncode not in success_exit_status:
                 if log:
                     log_process_failure(sandbox, cmdline, returncode)
                 if ARG_DEBUG_SHELL.get():