systemctl: use pid_is_valid() where appropriate
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Tue, 3 Oct 2017 11:13:06 +0000 (12:13 +0100)
committerAlan Jenkins <alan.christopher.jenkins@gmail.com>
Wed, 4 Oct 2017 14:40:11 +0000 (15:40 +0100)
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

index c569663..ca03fb4 100644 (file)
@@ -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,