]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: remove "misuse" of getpgid() in systemd-shutdown 7226/head
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Mon, 30 Oct 2017 16:10:37 +0000 (16:10 +0000)
committerAlan Jenkins <alan.christopher.jenkins@gmail.com>
Mon, 30 Oct 2017 16:10:37 +0000 (16:10 +0000)
Using `kill()`  with a signal of 0 is a slightly more documented idiom for
checking whether a process still exists.  It is mentioned explicitly in
man pages.  This avoids the need to comment the call as "misuse".
A comment is still necessary - in fact this idiom is even more confusing if
you don't know how it works.  But it's easy enough to explain.

src/core/killall.c

index 5e914e478d3d90796cbeaa37dd13c04aea337c0e..fe5320e8136ce87561a300f05f9647aa8792e53d 100644 (file)
@@ -129,9 +129,9 @@ static void wait_for_children(Set *pids, sigset_t *mask) {
                  * might not be our child. */
                 SET_FOREACH(p, pids, i) {
 
-                        /* We misuse getpgid as a check whether a
-                         * process still exists. */
-                        if (getpgid(PTR_TO_PID(p)) >= 0)
+                        /* kill(pid, 0) sends no signal, but it tells
+                         * us whether the process still exists. */
+                        if (kill(PTR_TO_PID(p), 0) == 0)
                                 continue;
 
                         if (errno != ESRCH)