tree-wide: use pid_is_valid() at more places
authorLennart Poettering <lennart@poettering.net>
Thu, 31 Aug 2017 08:25:06 +0000 (10:25 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 31 Aug 2017 13:45:04 +0000 (15:45 +0200)
src/basic/process-util.c
src/core/dbus-manager.c
src/login/logind-dbus.c
src/machine/machined-dbus.c
src/systemctl/systemctl.c

index 056a8b8..e4cde65 100644 (file)
@@ -475,7 +475,7 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
         assert(field);
         assert(uid);
 
-        if (pid < 0)
+        if (!pid_is_valid(pid))
                 return -EINVAL;
 
         p = procfs_file_alloca(pid, "status");
@@ -788,7 +788,7 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) {
 bool pid_is_unwaited(pid_t pid) {
         /* Checks whether a PID is still valid at all, including a zombie */
 
-        if (pid < 0)
+        if (!pid_is_valid(pid))
                 return false;
 
         if (pid <= 1) /* If we or PID 1 would be dead and have been waited for, this code would not be running */
@@ -808,7 +808,7 @@ bool pid_is_alive(pid_t pid) {
 
         /* Checks whether a PID is still valid and not a zombie */
 
-        if (pid < 0)
+        if (!pid_is_valid(pid))
                 return false;
 
         if (pid <= 1) /* If we or PID 1 would be a zombie, this code would not be running */
@@ -827,7 +827,7 @@ bool pid_is_alive(pid_t pid) {
 int pid_from_same_root_fs(pid_t pid) {
         const char *root;
 
-        if (pid < 0)
+        if (!pid_is_valid(pid))
                 return false;
 
         if (pid == 0 || pid == getpid_cached())
index f87b52a..c91d565 100644 (file)
@@ -446,7 +446,7 @@ static int method_get_unit_by_pid(sd_bus_message *message, void *userdata, sd_bu
         r = sd_bus_message_read(message, "u", &pid);
         if (r < 0)
                 return r;
-        if (pid < 0)
+        if (!pid_is_valid((pid_t) pid))
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PID " PID_FMT, pid);
 
         if (pid == 0) {
index d66022f..1aa6760 100644 (file)
@@ -344,7 +344,7 @@ static int method_get_session_by_pid(sd_bus_message *message, void *userdata, sd
         r = sd_bus_message_read(message, "u", &pid);
         if (r < 0)
                 return r;
-        if (pid < 0)
+        if (!pid_is_valid((pid_t) pid))
                 return -EINVAL;
 
         if (pid == 0) {
@@ -407,7 +407,7 @@ static int method_get_user_by_pid(sd_bus_message *message, void *userdata, sd_bu
         r = sd_bus_message_read(message, "u", &pid);
         if (r < 0)
                 return r;
-        if (pid < 0)
+        if (!pid_is_valid((pid_t) pid))
                 return -EINVAL;
 
         if (pid == 0) {
index c9b92d2..6618ec3 100644 (file)
@@ -199,7 +199,7 @@ static int method_get_machine_by_pid(sd_bus_message *message, void *userdata, sd
         if (r < 0)
                 return r;
 
-        if (pid < 0)
+        if (!pid_is_valid((pid_t) pid))
                 return -EINVAL;
 
         if (pid == 0) {
index d0c7ed7..79e9ac9 100644 (file)
@@ -3348,8 +3348,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 %" PRIu32 ".", pid);
+                        return -ERANGE;
+                }
 
                 if (!strv_contains(sv,
                                    IN_SET(a,