1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

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.

(cherry picked from commit 7ffa6ed41e)
This commit is contained in:
Simon Tatham 2020-05-02 16:11:19 +01:00
parent b22b4cc19f
commit 426a2048cc

View File

@ -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;
@ -1248,14 +1257,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;