Skip to content

Commit 2a19d45

Browse files
committed
run.py: stop hiding sandbox and recommend --debug on sandbox failure
As discussed in systemd#3948 and systemd#3992, logging commands failing in a sandbox without ever mentioning that a sandbox was in use is misleading and very time-consuming; notably because paths look real but they are not. To remove this confusion and cost, simply add one short line mentioning that a sandbox was involved when the failure happened + recommend to re-run with --debug to display bind mounts and other important information. Also separate the command and error message on different lines for better readability and re-usability. Just for the record: before commit 7e7a3c7 ("Don't log sandbox for every command"), `run.py` was logging sandbox commands every time which was too verbose and unreadable. That commit said "... but still log the full sandbox if a command fails" and it did that do in `__init__.py` - but not always in `run.py`. After that commit, the sandbox was logged by `run.py` only in --debug mode and became completely invisible otherwise. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent d44aae1 commit 2a19d45

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

mkosi/run.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,22 @@ def fork_and_wait(target: Callable[..., None], *args: Any, **kwargs: Any) -> Non
106106
raise subprocess.CalledProcessError(rc, ["self"])
107107

108108

109+
def log_sandbox_issue(sandbox: Sequence[str], cmdline: Sequence[str], errmsg: str) -> None:
110+
if ARG_DEBUG.get():
111+
# Complete but very long and hard to read. It could be reusable.
112+
logging.error(f"{shlex.join(['mkosi-sandbox', *sandbox, *cmdline])}")
113+
else:
114+
logging.error("sandbox command omitted, rerun with --debug to see full command with bind mounts")
115+
logging.error(f"{shlex.join(cmdline)}")
116+
117+
logging.error(errmsg)
118+
119+
109120
def log_process_failure(sandbox: Sequence[str], cmdline: Sequence[str], returncode: int) -> None:
110121
if -returncode in (signal.SIGINT, signal.SIGTERM):
111122
logging.error(f"Interrupted by {signal.Signals(-returncode).name} signal")
112123
elif returncode < 0:
113-
logging.error(
114-
f'"{shlex.join(["mkosi-sandbox", *sandbox, *cmdline] if ARG_DEBUG.get() else cmdline)}"'
115-
f" was killed by {signal.Signals(-returncode).name} signal."
116-
)
124+
log_sandbox_issue(sandbox, cmdline, f" was killed by {signal.Signals(-returncode).name} signal.")
117125
elif returncode == 127 and cmdline[0] != "mkosi":
118126
# Anything invoked beneath /work is a script that we mount into place (so we know it exists). If one
119127
# of these scripts fails with exit code 127, it's either because the script interpreter was not
@@ -126,10 +134,7 @@ def log_process_failure(sandbox: Sequence[str], cmdline: Sequence[str], returnco
126134
else:
127135
logging.error(f"{cmdline[0]} not found.")
128136
else:
129-
logging.error(
130-
f'"{shlex.join(["mkosi-sandbox", *sandbox, *cmdline] if ARG_DEBUG.get() else cmdline)}"'
131-
f" returned non-zero exit code {returncode}."
132-
)
137+
log_sandbox_issue(sandbox, cmdline, f" returned non-zero exit code {returncode}.")
133138

134139

135140
def run(

0 commit comments

Comments
 (0)