From 4ece43a02961dc6726e97b05caca9a3c53793826 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 10 Jul 2023 09:35:46 +0000 Subject: [PATCH] Loop around waitpid in client, from Azat Khuzhin. --- client.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/client.c b/client.c index 4f91d30e..be17540c 100644 --- a/client.c +++ b/client.c @@ -526,11 +526,22 @@ client_signal(int sig) { struct sigaction sigact; int status; + pid_t pid; log_debug("%s: %s", __func__, strsignal(sig)); - if (sig == SIGCHLD) - waitpid(WAIT_ANY, &status, WNOHANG); - else if (!client_attached) { + if (sig == SIGCHLD) { + for (;;) { + pid = waitpid(WAIT_ANY, &status, WNOHANG); + if (pid == 0) + break; + if (pid == -1) { + if (errno == ECHILD) + break; + log_debug("waitpid failed: %s", + strerror(errno)); + } + } + } else if (!client_attached) { if (sig == SIGTERM || sig == SIGHUP) proc_exit(client_proc); } else {