]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Revert "tree-wide: use pid_is_valid() at more places"
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Tue, 3 Oct 2017 11:05:24 +0000 (12:05 +0100)
committerAlan Jenkins <alan.christopher.jenkins@gmail.com>
Tue, 3 Oct 2017 11:43:24 +0000 (12:43 +0100)
This reverts commit ee043777be58251e7441b4f04594e9e3792d7fb2.

It broke almost everywhere it touched.  The places that
handn't been converted, were mostly followed by special
handling for the invalid PID `0`.  That explains why they
tested for `pid < 0` instead of `pid <= 0`.

I think that one was the first commit I reviewed, heh.

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 ab661a8f1632c322965345508a4ce3023b2228c0..44ebf49f90db777370c79a1748c37aef46f9441e 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_is_valid(pid))
+        if (pid < 0)
                 return -EINVAL;
 
         p = procfs_file_alloca(pid, "status");
@@ -787,7 +787,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_is_valid(pid))
+        if (pid < 0)
                 return false;
 
         if (pid <= 1) /* If we or PID 1 would be dead and have been waited for, this code would not be running */
@@ -807,7 +807,7 @@ bool pid_is_alive(pid_t pid) {
 
         /* Checks whether a PID is still valid and not a zombie */
 
-        if (!pid_is_valid(pid))
+        if (pid < 0)
                 return false;
 
         if (pid <= 1) /* If we or PID 1 would be a zombie, this code would not be running */
@@ -826,7 +826,7 @@ bool pid_is_alive(pid_t pid) {
 int pid_from_same_root_fs(pid_t pid) {
         const char *root;
 
-        if (!pid_is_valid(pid))
+        if (pid < 0)
                 return false;
 
         if (pid == 0 || pid == getpid_cached())
index c91d56598bcc044404f287d265bd57f112554fc2..f87b52a266bb100c6a20e6f12e4139adb1e92946 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_is_valid((pid_t) pid))
+        if (pid < 0)
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PID " PID_FMT, pid);
 
         if (pid == 0) {
index 1aa67606652f57c82e6123f1b95b185266c49410..d66022f8023dc44fe11fda6b94dc628f113befba 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_is_valid((pid_t) pid))
+        if (pid < 0)
                 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_is_valid((pid_t) pid))
+        if (pid < 0)
                 return -EINVAL;
 
         if (pid == 0) {
index 6618ec30f16e9c1826521dc9132420abd5aab1e8..c9b92d2765ab0df85c7f10d61833e05d892d1669 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_is_valid((pid_t) pid))
+        if (pid < 0)
                 return -EINVAL;
 
         if (pid == 0) {
index 897fc48b9895e06242fc01378aa645f2daf93c2a..c569663bab561161a33f07f257c6ba28afde7886 100644 (file)
@@ -3375,10 +3375,8 @@ static int logind_check_inhibitors(enum action a) {
                 if (!sv)
                         return log_oom();
 
-                if (!pid_is_valid((pid_t) pid)) {
-                        log_error("Invalid PID %" PRIu32 ".", pid);
-                        return -ERANGE;
-                }
+                if ((pid_t) pid < 0)
+                        return log_error_errno(ERANGE, "Bad PID %"PRIu32": %m", pid);
 
                 if (!strv_contains(sv,
                                    IN_SET(a,