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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-01-04 14:07:57 +01:00
parent 22aa8c4879
commit 4a4be1015b
2 changed files with 7 additions and 7 deletions
+5 -5
View File
@@ -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) {
+2 -2
View File
@@ -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);
}
}