[PATCH] daemon: handle EINTR failures from waitpid()

Carlo Marcelo Arenas Belón
2025-06-30T04:13:34Z

Since 695605b508 (git-daemon: Simplify dead-children reaping logic,
2008-08-14), the logic to check for zombie children was moved out of
the SIGCHLD signal handler, but adding checks for a failed waitpid()
were missed, with the possibility that a badly timed signal could
prevent the promptly reaping of those defunct processes.

After the refactoring of 30e1560230 (daemon: use run-command api for
async serving, 2010-11-04), that reproduced that bug, a single
process could be skipped from reaping, so prevent that by adding the
missing error handling, and while at it make sure that ECHILD (or
other errors) are correctly reported as a BUG().

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
daemon.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/daemon.c b/daemon.c
index d1be61fd57..16ae66a2da 100644
--- a/daemon.c
+++ b/daemon.c
@@ -864,8 +864,11 @@ static void check_dead_children(void)
live_children--;
child_process_clear(&blanket->cld);
free(blanket);
- } else
+ } else if (!pid)
cradle = &blanket->next;
+ else if (errno != EINTR)
+ BUG("invalid child '%" PRIuMAX "'",
+ (uintmax_t)blanket->cld.pid);
}

static struct strvec cld_argv = STRVEC_INIT;
--
2.50.0.132.g32f443f09a.dirty