From: Daan De Meyer Date: Sat, 13 Apr 2024 08:45:48 +0000 (+0200) Subject: Introduce success_exit_status argument for run() and spawn() X-Git-Tag: v23~4^2~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc1efac90126fb79835860a67100c8d09f77b6f3;p=thirdparty%2Fmkosi.git Introduce success_exit_status argument for run() and spawn() --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 9495bd950..edae1bc55 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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: diff --git a/mkosi/run.py b/mkosi/run.py index 3eef72ab5..ea2b9a0e0 100644 --- a/mkosi/run.py +++ b/mkosi/run.py @@ -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():