]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: make pid_is_unwaited() wrapper around pidref version
authorMike Yuan <me@yhndnzj.com>
Fri, 29 Nov 2024 15:54:29 +0000 (16:54 +0100)
committerMike Yuan <me@yhndnzj.com>
Sat, 4 Jan 2025 16:48:22 +0000 (17:48 +0100)
src/basic/process-util.c

index f412d202eb8765f4e6e96665b5bf0797a3cd93ee..53ac2717e38124bc55ee517f7fd8532e5c2ea6ff 100644 (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;