From: Alan Jenkins Date: Mon, 30 Oct 2017 16:10:37 +0000 (+0000) Subject: core: remove "misuse" of getpgid() in systemd-shutdown X-Git-Tag: v236~277^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F7226%2Fhead;p=thirdparty%2Fsystemd.git core: remove "misuse" of getpgid() in systemd-shutdown 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. --- diff --git a/src/core/killall.c b/src/core/killall.c index 5e914e478d3..fe5320e8136 100644 --- a/src/core/killall.c +++ b/src/core/killall.c @@ -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)