process-util: add pidref_is_unwaited() and make pid_is_unwaited() return errors
This commit is contained in:
@@ -1045,11 +1045,11 @@ int pidref_is_my_child(const PidRef *pid) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool pid_is_unwaited(pid_t pid) {
|
||||
int pid_is_unwaited(pid_t pid) {
|
||||
/* Checks whether a PID is still valid at all, including a zombie */
|
||||
|
||||
if (pid < 0)
|
||||
return false;
|
||||
return -ESRCH;
|
||||
|
||||
if (pid <= 1) /* If we or PID 1 would be dead and have been waited for, this code would not be running */
|
||||
return true;
|
||||
@@ -1063,6 +1063,24 @@ bool pid_is_unwaited(pid_t pid) {
|
||||
return errno != ESRCH;
|
||||
}
|
||||
|
||||
int pidref_is_unwaited(const PidRef *pid) {
|
||||
int r;
|
||||
|
||||
if (!pidref_is_set(pid))
|
||||
return -ESRCH;
|
||||
|
||||
if (pid->pid == 1 || pidref_is_self(pid))
|
||||
return true;
|
||||
|
||||
r = pidref_kill(pid, 0);
|
||||
if (r == -ESRCH)
|
||||
return false;
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int pid_is_alive(pid_t pid) {
|
||||
int r;
|
||||
|
||||
|
||||
@@ -88,7 +88,8 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value);
|
||||
|
||||
int pid_is_alive(pid_t pid);
|
||||
int pidref_is_alive(const PidRef *pidref);
|
||||
bool pid_is_unwaited(pid_t pid);
|
||||
int pid_is_unwaited(pid_t pid);
|
||||
int pidref_is_unwaited(const PidRef *pidref);
|
||||
int pid_is_my_child(pid_t pid);
|
||||
int pidref_is_my_child(const PidRef *pidref);
|
||||
int pid_from_same_root_fs(pid_t pid);
|
||||
|
||||
Reference in New Issue
Block a user