From: Mike Yuan Date: Fri, 29 Nov 2024 15:54:29 +0000 (+0100) Subject: process-util: make pid_is_unwaited() wrapper around pidref version X-Git-Tag: v258-rc1~1704^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=223d45567058e6009e42c2b52f78b0cdd61a3cdc;p=thirdparty%2Fsystemd.git process-util: make pid_is_unwaited() wrapper around pidref version --- diff --git a/src/basic/process-util.c b/src/basic/process-util.c index f412d202eb8..53ac2717e38 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -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;