From a71b0c04617e036bc2ba9446d6b08719c057a364 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Mar 2023 15:44:30 +0200 Subject: [PATCH] gmain: simplify handling child watchers in dispatch_unix_signals_unlocked() - if a child watch source has "using_pidfd", it is never linked in the unix_child_watches list. Drop that check. - replace the deep nested if, with an early "continue" in the loop, if we detect there is nothing to do. It makes the code easier to read. --- glib/gmain.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/glib/gmain.c b/glib/gmain.c index d50fd8315..2e829476f 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -5695,31 +5695,30 @@ dispatch_unix_signals_unlocked (void) for (node = unix_child_watches; node; node = node->next) { GChildWatchSource *source = node->data; + pid_t pid; - if (!source->using_pidfd && - !g_atomic_int_get (&source->child_exited)) + if (g_atomic_int_get (&source->child_exited)) + continue; + + do { - pid_t pid; - do - { - g_assert (source->pid > 0); + g_assert (source->pid > 0); - pid = waitpid (source->pid, &source->child_status, WNOHANG); - if (pid > 0) - { - g_atomic_int_set (&source->child_exited, TRUE); - wake_source ((GSource *) source); - } - else if (pid == -1 && errno == ECHILD) - { - g_warning ("GChildWatchSource: Exit status of a child process was requested but ECHILD was received by waitpid(). See the documentation of g_child_watch_source_new() for possible causes."); - source->child_status = 0; - g_atomic_int_set (&source->child_exited, TRUE); - wake_source ((GSource *) source); - } + pid = waitpid (source->pid, &source->child_status, WNOHANG); + if (pid > 0) + { + g_atomic_int_set (&source->child_exited, TRUE); + wake_source ((GSource *) source); + } + else if (pid == -1 && errno == ECHILD) + { + g_warning ("GChildWatchSource: Exit status of a child process was requested but ECHILD was received by waitpid(). See the documentation of g_child_watch_source_new() for possible causes."); + source->child_status = 0; + g_atomic_int_set (&source->child_exited, TRUE); + wake_source ((GSource *) source); } - while (pid == -1 && errno == EINTR); } + while (pid == -1 && errno == EINTR); } }