From b30f77cd125db1cca0eca95ba2d6dcbc5fffe45d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 17 Dec 2025 22:51:26 +0100 Subject: [PATCH 1/4] ssh-generator: reword error message We have two error messages with exactly the same message. Let's change one so that it is possible to distinguish them in logs. --- src/ssh-generator/ssh-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ssh-generator/ssh-util.c b/src/ssh-generator/ssh-util.c index 48cb662b71..b7af045487 100644 --- a/src/ssh-generator/ssh-util.c +++ b/src/ssh-generator/ssh-util.c @@ -35,6 +35,6 @@ int vsock_get_local_cid_or_warn(unsigned *ret) { return 0; } if (r < 0) - return log_error_errno(r, "Failed to query local AF_VSOCK CID: %m"); + return log_error_errno(r, "Failed to query host's AF_VSOCK CID: %m"); return 1; } From 1ee73c884e4fecfae57433b9d50caa72816403d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 4 Jan 2026 12:18:38 +0100 Subject: [PATCH 2/4] basic/process-util: use synthetic errno in two more places --- src/basic/process-util.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 42709202a5..92b851573f 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -894,14 +894,12 @@ int pidref_wait_for_terminate_and_check(const char *name, PidRef *pidref, WaitFl return status.si_status; - } else if (IN_SET(status.si_code, CLD_KILLED, CLD_DUMPED)) { + } 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)); - log_full(prio, "%s terminated by signal %s.", strna(name), signal_to_string(status.si_status)); - return -EPROTO; - } - - log_full(prio, "%s failed due to unknown reason.", strna(name)); - return -EPROTO; + return log_full_errno(prio, SYNTHETIC_ERRNO(EPROTO), + "%s failed due to unknown reason.", strna(name)); } int kill_and_sigcont(pid_t pid, int sig) { From 22aa8c48799b51df7e8b176bbec5645174fd9261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 4 Jan 2026 12:21:52 +0100 Subject: [PATCH 3/4] basic/process-util: reduce scope of variables --- src/basic/process-util.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 92b851573f..e63f9fad67 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -389,11 +389,6 @@ int container_get_leader(const char *machine, pid_t *pid) { } int pid_is_kernel_thread(pid_t pid) { - _cleanup_free_ char *line = NULL; - unsigned long long flags; - size_t l, i; - const char *p; - char *q; int r; if (IN_SET(pid, 0, 1) || pid == getpid_cached()) /* pid 1, and we ourselves certainly aren't a kernel thread */ @@ -401,7 +396,8 @@ int pid_is_kernel_thread(pid_t pid) { if (!pid_is_valid(pid)) return -EINVAL; - p = procfs_file_alloca(pid, "stat"); + const char *p = procfs_file_alloca(pid, "stat"); + _cleanup_free_ char *line = NULL; r = read_one_line_file(p, &line); if (r == -ENOENT) return -ESRCH; @@ -409,14 +405,14 @@ int pid_is_kernel_thread(pid_t pid) { return r; /* Skip past the comm field */ - q = strrchr(line, ')'); + char *q = strrchr(line, ')'); if (!q) return -EINVAL; q++; /* Skip 6 fields to reach the flags field */ - for (i = 0; i < 6; i++) { - l = strspn(q, WHITESPACE); + for (size_t i = 0; i < 6; i++) { + size_t l = strspn(q, WHITESPACE); if (l < 1) return -EINVAL; q += l; @@ -428,7 +424,7 @@ int pid_is_kernel_thread(pid_t pid) { } /* Skip preceding whitespace */ - l = strspn(q, WHITESPACE); + size_t l = strspn(q, WHITESPACE); if (l < 1) return -EINVAL; q += l; @@ -439,6 +435,7 @@ int pid_is_kernel_thread(pid_t pid) { return -EINVAL; q[l] = 0; + unsigned long long flags; r = safe_atollu(q, &flags); if (r < 0) return r; From 4a4be1015b1a3c9efa974cbb1dbe1c776aab4f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 4 Jan 2026 12:25:32 +0100 Subject: [PATCH 4/4] 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 e63f9fad67..1ff59dd374 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 786594c9ee..4df17d2d69 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); } }