summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-10-27 14:02:45 +0100
committerLennart Poettering <lennart@poettering.net>2015-10-27 14:02:45 +0100
commit5fd9b2c5467b0a42ccdabc7eb8e516d512609a8e (patch)
treed3ccfc90700547654e15ab8ba2bbe81bb5fa3928 /src/basic
parent6bc73acb01e2782f0ef3ec70dde3dc3f5b5da081 (diff)
process-util: make some minor corrections to PID live detection
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/process-util.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index 0b7e3010e0..a737686ab0 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -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;