X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Fprocess-util.c;h=5825944c90414a954f14a3fb4c05de9ff60b55cc;hb=27edf6f36e27bff66b04908b4dcebd359ae08116;hp=25044dfaa7bc916bb4768307c082d1fa337d691f;hpb=3cd22db822df747636dcf30ebb8ec5d16bb71880;p=elogind.git diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 25044dfaa..5825944c9 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -368,7 +368,6 @@ int get_process_environ(pid_t pid, char **env) { return 0; } -#endif // 0 int get_parent_of_pid(pid_t pid, pid_t *_ppid) { int r; @@ -414,6 +413,7 @@ int get_parent_of_pid(pid_t pid, pid_t *_ppid) { return 0; } +#endif // 0 int wait_for_terminate(pid_t pid, siginfo_t *status) { siginfo_t dummy; @@ -556,9 +556,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; @@ -570,9 +573,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;