From: Daan De Meyer Date: Thu, 4 Apr 2024 18:29:15 +0000 (+0200) Subject: Check in spawn() whether the command we're trying to run is available X-Git-Tag: v23~29^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=refs%2Fpull%2F2593%2Fhead;p=thirdparty%2Fmkosi.git Check in spawn() whether the command we're trying to run is available Currently, if we try to run a command within a sandbox, we fail with an unclear error if the program is not installed. This is because our FileNotFoundError exception handler is never triggered as the program we run via subprocess is almost always "sh" or "bwrap". Let's make sure we also check for the actual program we're going to run in the sandbox and show a clear error if it's not available. --- diff --git a/mkosi/run.py b/mkosi/run.py index 5b579586e..e7a66dd19 100644 --- a/mkosi/run.py +++ b/mkosi/run.py @@ -244,6 +244,14 @@ def spawn( # expect it to pick. assert nfd == SD_LISTEN_FDS_START + i + # First, check if the sandbox works at all before executing the command. + if sandbox and (rc := subprocess.run(sandbox + ["true"]).returncode) != 0: + log_process_failure(sandbox, cmdline, rc) + raise subprocess.CalledProcessError(rc, sandbox + cmdline) + + if subprocess.run(sandbox + ["sh", "-c", f"command -v {cmdline[0]}"], stdout=subprocess.DEVNULL).returncode != 0: + die(f"{cmdline[0]} not found.", hint=f"Is {cmdline[0]} installed on the host system?") + if ( foreground and sandbox and