process-util: make pid_is_unwaited() wrapper around pidref version

This commit is contained in:
Mike Yuan
2025-01-04 17:48:22 +01:00
parent 47f64104d1
commit 223d455670
+10 -18
View File
@@ -1110,27 +1110,11 @@ int pid_is_my_child(pid_t pid) {
return pidref_is_my_child(&PIDREF_MAKE_FROM_PID(pid));
}
int pid_is_unwaited(pid_t pid) {
/* Checks whether a PID is still valid at all, including a zombie */
if (pid < 0)
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;
if (pid == getpid_cached())
return true;
if (kill(pid, 0) >= 0)
return true;
return errno != ESRCH;
}
int pidref_is_unwaited(const PidRef *pid) {
int r;
/* Checks whether a PID is still valid at all, including a zombie */
if (!pidref_is_set(pid))
return -ESRCH;
@@ -1149,6 +1133,14 @@ int pidref_is_unwaited(const PidRef *pid) {
return true;
}
int pid_is_unwaited(pid_t pid) {
if (pid == 0)
return true;
return pidref_is_unwaited(&PIDREF_MAKE_FROM_PID(pid));
}
int pid_is_alive(pid_t pid) {
int r;