From 7ffa6ed41eaa1e8b347f2b930838a441e168a498 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 2 May 2020 16:11:19 +0100 Subject: [PATCH] pty_backend_create: set up SIGCHLD handler earlier. Mark Wooding points out that when running with the +ut flag, we close pty_utmp_helper_pipe during pty backend setup, which causes the previously forked helper process to terminate. If that termination happens quickly enough, then the code later in pty_backend_create won't have set up the SIGCHLD handler and its pipe yet, so when we get to the main event loop, we'll fail to notice that subprocess waiting to be reaped, and leave it lying around as a zombie. An easy fix is to move the handler and pipe setup to before the code that potentially closes pty_utmp_helper_pipe, so that there isn't a race condition any more. --- unix/uxpty.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/unix/uxpty.c b/unix/uxpty.c index 346fdb55..09c5ecb0 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -890,6 +890,15 @@ Backend *pty_backend_create( pty->fds[i].pty = pty; } + if (pty_signal_pipe[0] < 0) { + if (pipe(pty_signal_pipe) < 0) { + perror("pipe"); + exit(1); + } + cloexec(pty_signal_pipe[0]); + cloexec(pty_signal_pipe[1]); + } + pty->seat = seat; pty->backend.vt = &pty_backend; @@ -1250,14 +1259,6 @@ Backend *pty_backend_create( add234(ptys_by_pid, pty); } - if (pty_signal_pipe[0] < 0) { - if (pipe(pty_signal_pipe) < 0) { - perror("pipe"); - exit(1); - } - cloexec(pty_signal_pipe[0]); - cloexec(pty_signal_pipe[1]); - } pty_uxsel_setup(pty); return &pty->backend;