]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
inhibit: fix borked double logging on error 40271/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 4 Jan 2026 11:25:32 +0000 (12:25 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 4 Jan 2026 13:07:57 +0000 (14:07 +0100)
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
src/login/inhibit.c

index e63f9fad6716ed19273cd06b40639c922332293c..1ff59dd374a5067e1c1b9f22802dd5f89f2d18d6 100644 (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) {
index 786594c9ee33d4a1f8d42a2049fa1bbd0aacc160..4df17d2d69973b77c9993bb715b5472f2598b31b 100644 (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);
         }
 }