From bc5de94397d4bea45540427247c09bc5d378b0d2 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. --- usr.bin/tmux/client.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c index b5c4d36db39..16373e5d3d6 100644 --- a/usr.bin/tmux/client.c +++ b/usr.bin/tmux/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.159 2023/01/06 07:09:27 nicm Exp $ */ +/* $OpenBSD: client.c,v 1.160 2023/07/10 09:35:46 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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 { -- 2.20.1