From 116dac29ccc99ff498edd7dfcda0f456ce47c3ef Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 25 Nov 2017 21:49:31 +0000 Subject: [PATCH] Reinstate the SIGCHLD handler in ptermapp. Detecting that the child process in a pterm has terminated is important for _any_ kind of pterm, so it's a mistake to put the signal handler setup _solely_ inside the optional pty_pre_init function which does the privileged setup and forks off a utmp watchdog process. Now the signal handler is installed even in the GtkApplication-based multi-window front end to pterm, meaning it will exist even on OS X. --- unix/uxpty.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/unix/uxpty.c b/unix/uxpty.c index 618fe9bd..4387ad8f 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -261,13 +261,20 @@ static void cleanup_utmp(void) } #endif -#ifndef NO_PTY_PRE_INIT static void sigchld_handler(int signum) { if (write(pty_signal_pipe[1], "x", 1) <= 0) /* not much we can do about it */; } -#endif + +static void pty_setup_sigchld_handler(void) +{ + static int setup = FALSE; + if (!setup) { + putty_signal(SIGCHLD, sigchld_handler); + setup = TRUE; + } +} #ifndef OMIT_UTMP static void fatal_sig_handler(int signum) @@ -433,7 +440,7 @@ void pty_pre_init(void) /* set the child signal handler straight away; it needs to be set * before we ever fork. */ - putty_signal(SIGCHLD, sigchld_handler); + pty_setup_sigchld_handler(); pty->master_fd = pty->slave_fd = -1; #ifndef OMIT_UTMP pty_stamped_utmp = FALSE; @@ -790,6 +797,12 @@ static const char *pty_init(void *frontend, void **backend_handle, Conf *conf, windowid = get_windowid(pty->frontend); #endif + /* + * Set up the signal handler to catch SIGCHLD, if pty_pre_init + * didn't already do it. + */ + pty_setup_sigchld_handler(); + /* * Fork and execute the command. */