]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: make some minor corrections to PID live detection
authorLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 13:02:45 +0000 (14:02 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 13:02:45 +0000 (14:02 +0100)
src/basic/process-util.c

index 0b7e3010e0693bf78fbe5712880ed9a6aaea69ed..a737686ab0ccd8687ab0ad95e345aadc99c334c5 100644 (file)
@@ -595,9 +595,12 @@ 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 < 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 */
+                return true;
+
         if (kill(pid, 0) >= 0)
                 return true;
 
@@ -609,9 +612,12 @@ bool pid_is_alive(pid_t pid) {
 
         /* Checks whether a PID is still valid and not a zombie */
 
-        if (pid <= 0)
+        if (pid < 0)
                 return false;
 
+        if (pid <= 1) /* If we or PID 1 would be a zombie, this code would not be running */
+                return true;
+
         r = get_process_state(pid);
         if (r == -ESRCH || r == 'Z')
                 return false;