]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Don't log sandbox for every command
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 12 Mar 2024 21:29:56 +0000 (21:29 +0000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 13 Mar 2024 10:11:29 +0000 (11:11 +0100)
This is excessively verbose. Let's instead log only the command
we're executing but still log the full sandbox if a command fails.

mkosi/__init__.py
mkosi/run.py

index 3ccfbb2d1bc744cef6643cb14d92346e8420e369..0dd22f300cbcb5a8287f85c7d60bc03cc62db802 100644 (file)
@@ -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)
 
 
index 61a17bcb1634d9dd9cba16dbf4f8b99c679d4ef6..0574d261bad1e93d996b72961430a0d226ef8a90 100644 (file)
@@ -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: