From 4a4be1015b1a3c9efa974cbb1dbe1c776aab4f05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 4 Jan 2026 12:25:32 +0100 Subject: [PATCH] inhibit: fix borked double logging on error Previously, if execution failed, we'd log at error level both from the child and the parent, and we were using a bogus variable for the argument name: $ build/systemd-inhibit list Failed to execute : No such file or directory list failed with exit status 1. In general, we can and should assume that the program the user is calling is well behaved, so it'll log the error on its own if appropriate. So we shouldn't log on "normal errors", but only if the child is terminated by a signal. And since the program name is controlled by the user, use quotes everywhere to avoid ambiguity. Now: $ build/systemd-inhibit false (nothing) $ build/systemd-inhibit bash -c 'kill -SEGV $$' src/basic/process-util.c:895: 'bash' terminated by signal SEGV. --- src/basic/process-util.c | 10 +++++----- src/login/inhibit.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/basic/process-util.c b/src/basic/process-util.c index e63f9fad671..1ff59dd374a 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -880,23 +880,23 @@ int pidref_wait_for_terminate_and_check(const char *name, PidRef *pidref, WaitFl siginfo_t status; r = pidref_wait_for_terminate(pidref, &status); if (r < 0) - return log_full_errno(prio, r, "Failed to wait for %s: %m", strna(name)); + return log_full_errno(prio, r, "Failed to wait for '%s': %m", strna(name)); if (status.si_code == CLD_EXITED) { if (status.si_status != EXIT_SUCCESS) log_full(flags & WAIT_LOG_NON_ZERO_EXIT_STATUS ? LOG_ERR : LOG_DEBUG, - "%s failed with exit status %i.", strna(name), status.si_status); + "'%s' failed with exit status %i.", strna(name), status.si_status); else - log_debug("%s succeeded.", name); + log_debug("'%s' succeeded.", name); return status.si_status; } else if (IN_SET(status.si_code, CLD_KILLED, CLD_DUMPED)) return log_full_errno(prio, SYNTHETIC_ERRNO(EPROTO), - "%s terminated by signal %s.", strna(name), signal_to_string(status.si_status)); + "'%s' terminated by signal %s.", strna(name), signal_to_string(status.si_status)); return log_full_errno(prio, SYNTHETIC_ERRNO(EPROTO), - "%s failed due to unknown reason.", strna(name)); + "'%s' failed due to unknown reason.", strna(name)); } int kill_and_sigcont(pid_t pid, int sig) { diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 786594c9ee3..4df17d2d699 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -368,11 +368,11 @@ static int run(int argc, char *argv[]) { /* Child */ execvp(arguments[0], arguments); log_open(); - log_error_errno(errno, "Failed to execute %s: %m", argv[optind]); + log_error_errno(errno, "Failed to execute '%s': %m", arguments[0]); _exit(EXIT_FAILURE); } - return pidref_wait_for_terminate_and_check(argv[optind], &pidref, WAIT_LOG); + return pidref_wait_for_terminate_and_check(argv[optind], &pidref, WAIT_LOG_ABNORMAL); } } -- 2.47.3