Loop around waitpid in client, from Azat Khuzhin.
authornicm <nicm@openbsd.org>
Mon, 10 Jul 2023 09:35:46 +0000 (09:35 +0000)
committernicm <nicm@openbsd.org>
Mon, 10 Jul 2023 09:35:46 +0000 (09:35 +0000)
usr.bin/tmux/client.c

index b5c4d36..16373e5 100644 (file)
@@ -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 <nicholas.marriott@gmail.com>
@@ -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 {