From: Daan De Meyer Date: Thu, 7 Dec 2023 11:50:23 +0000 (+0100) Subject: Log "Interrupted by ..." when we interrupt a child process X-Git-Tag: v20~103^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4a57cea50ea3a52ca998596f5cd30659873547d;p=thirdparty%2Fmkosi.git Log "Interrupted by ..." when we interrupt a child process Instead of logging the full command line with exit status, let's just log "Interrupted" when a child process is interrupted with CTRL+C. --- diff --git a/mkosi/run.py b/mkosi/run.py index 957b7c804..ec03f4fcf 100644 --- a/mkosi/run.py +++ b/mkosi/run.py @@ -228,6 +228,13 @@ def sigkill_to_sigterm() -> Iterator[None]: signal.SIGKILL = old +def log_process_failure(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}.") + + def run( cmdline: Sequence[PathString], check: bool = True, @@ -294,7 +301,7 @@ def run( die(f"{e.filename} not found.") except subprocess.CalledProcessError as e: if log: - logging.error(f"\"{shlex.join(cmdline)}\" returned non-zero exit code {e.returncode}.") + log_process_failure(cmdline, e.returncode) raise e finally: make_foreground_process(new_process_group=False) @@ -356,7 +363,7 @@ def spawn( die(f"{e.filename} not found.") except subprocess.CalledProcessError as e: if log: - logging.error(f"\"{shlex.join(cmdline)}\" returned non-zero exit code {e.returncode}.") + log_process_failure(cmdline, e.returncode) raise e finally: if foreground: @@ -441,8 +448,7 @@ def bwrap( result = run([*cmdline, *cmd], env=env, log=False, stdin=stdin, stdout=stdout, input=input) except subprocess.CalledProcessError as e: if log: - c = shlex.join(os.fspath(s) for s in cmd) - logging.error(f"\"{c}\" returned non-zero exit code {e.returncode}.") + log_process_failure([os.fspath(s) for s in cmd], e.returncode) if ARG_DEBUG_SHELL.get(): run([*cmdline, "sh"], stdin=sys.stdin, check=False, env=env, log=False) raise e