From 72b3f82e1771e1070853a084a6108082c59ab0cb Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Tue, 3 Oct 2017 12:13:06 +0100 Subject: [PATCH] systemctl: use pid_is_valid() where appropriate This was the one valid site in commit ee043777be58251e7441b4f04594e9e3792d7fb2. The second part of this hunk, avoiding using `%m` when we didn't actually have `errno` set, seems like a nice enough cleanup to be worthwhile on it's own. Also use PID_FMT to improve the error message we print (pid_t is signed). --- src/systemctl/systemctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index c569663..ca03fb4 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3375,8 +3375,10 @@ static int logind_check_inhibitors(enum action a) { if (!sv) return log_oom(); - if ((pid_t) pid < 0) - return log_error_errno(ERANGE, "Bad PID %"PRIu32": %m", pid); + if (!pid_is_valid((pid_t) pid)) { + log_error("Invalid PID "PID_FMT".", (pid_t) pid); + return -ERANGE; + } if (!strv_contains(sv, IN_SET(a, -- 2.7.4