From: Daan De Meyer Date: Tue, 12 Mar 2024 21:29:56 +0000 (+0000) Subject: Don't log sandbox for every command X-Git-Tag: v22~12^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e7a3c71696d66d1774abff3eff80d5032612c88;p=thirdparty%2Fmkosi.git Don't log sandbox for every command This is excessively verbose. Let's instead log only the command we're executing but still log the full sandbox if a command fails. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 3ccfbb2d1..0dd22f300 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -2659,23 +2659,25 @@ def run_tmpfiles(context: Context) -> None: *(f"--exclude-prefix={d}" for d in ("/tmp", "/var/tmp", "/run", "/proc", "/sys", "/dev")), ] + sandbox = context.sandbox( + options=[ + "--bind", context.root, context.root, + # 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) + ], + ) + result = run( cmdline, - sandbox=context.sandbox( - options=[ - "--bind", context.root, context.root, - # 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) - ], - ), + 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. if result.returncode not in (0, 65, 73): - log_process_failure(cmdline, result.returncode) + log_process_failure([str(s) for s in sandbox], cmdline, result.returncode) raise subprocess.CalledProcessError(result.returncode, cmdline) diff --git a/mkosi/run.py b/mkosi/run.py index 61a17bcb1..0574d261b 100644 --- a/mkosi/run.py +++ b/mkosi/run.py @@ -120,11 +120,14 @@ def sigkill_to_sigterm() -> Iterator[None]: signal.SIGKILL = old -def log_process_failure(cmdline: Sequence[str], returncode: int) -> None: +def log_process_failure(sandbox: Sequence[str], cmdline: Sequence[str], returncode: int) -> None: if returncode < 0: logging.error(f"Interrupted by {signal.Signals(-returncode).name} signal") else: - logging.error(f"\"{shlex.join(cmdline)}\" returned non-zero exit code {returncode}.") + logging.error( + f"\"{shlex.join([*sandbox, *cmdline] if ARG_DEBUG.get() else cmdline)}\" returned non-zero exit code " + f" {returncode}." + ) def run( @@ -146,7 +149,7 @@ def run( cmdline = [os.fspath(x) for x in cmdline] if ARG_DEBUG.get(): - logging.info(f"+ {shlex.join(sandbox + cmdline)}") + logging.info(f"+ {shlex.join(cmdline)}") if not stdout and not stderr: # Unless explicit redirection is done, print all subprocess @@ -207,7 +210,7 @@ def run( die(f"{e.filename} not found.") except subprocess.CalledProcessError as e: if log: - log_process_failure(cmdline, e.returncode) + log_process_failure(sandbox, cmdline, e.returncode) if ARG_DEBUG_SHELL.get(): subprocess.run( [*sandbox, "bash"], @@ -246,7 +249,7 @@ def spawn( cmdline = [os.fspath(x) for x in cmdline] if ARG_DEBUG.get(): - logging.info(f"+ {shlex.join(sandbox + cmdline)}") + logging.info(f"+ {shlex.join(cmdline)}") if not stdout and not stderr: # Unless explicit redirection is done, print all subprocess @@ -292,7 +295,7 @@ def spawn( die(f"{e.filename} not found.") except subprocess.CalledProcessError as e: if log: - log_process_failure(cmdline, e.returncode) + log_process_failure(sandbox, cmdline, e.returncode) raise e finally: if foreground: