mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-04-17 19:18:06 -05:00
xterm-class programs should exit when their primary child process
dies, rather than waiting around until the last open handle on the pty closes. [originally from svn r2044]
This commit is contained in:
parent
b3072e227e
commit
76cda50683
13
unix/pterm.c
13
unix/pterm.c
@ -710,6 +710,19 @@ gint motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
|
|||||||
gint timer_func(gpointer data)
|
gint timer_func(gpointer data)
|
||||||
{
|
{
|
||||||
/* struct gui_data *inst = (struct gui_data *)data; */
|
/* struct gui_data *inst = (struct gui_data *)data; */
|
||||||
|
extern int pty_child_is_dead(); /* declared in pty.c */
|
||||||
|
|
||||||
|
if (pty_child_is_dead()) {
|
||||||
|
/*
|
||||||
|
* The primary child process died. We could keep the
|
||||||
|
* terminal open for remaining subprocesses to output to,
|
||||||
|
* but conventional wisdom seems to feel that that's the
|
||||||
|
* Wrong Thing for an xterm-alike, so we bail out now. This
|
||||||
|
* would be easy enough to change or make configurable if
|
||||||
|
* necessary.
|
||||||
|
*/
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
term_update();
|
term_update();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
22
unix/pty.c
22
unix/pty.c
@ -6,8 +6,11 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include "putty.h"
|
#include "putty.h"
|
||||||
@ -20,10 +23,26 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int pty_master_fd;
|
int pty_master_fd;
|
||||||
|
static int pty_child_pid;
|
||||||
|
static sig_atomic_t pty_child_dead;
|
||||||
char **pty_argv;
|
char **pty_argv;
|
||||||
|
|
||||||
|
int pty_child_is_dead(void)
|
||||||
|
{
|
||||||
|
return pty_child_dead;
|
||||||
|
}
|
||||||
|
|
||||||
static void pty_size(void);
|
static void pty_size(void);
|
||||||
|
|
||||||
|
static void sigchld_handler(int signum)
|
||||||
|
{
|
||||||
|
pid_t pid;
|
||||||
|
int status;
|
||||||
|
pid = waitpid(-1, &status, WNOHANG);
|
||||||
|
if (pid == pty_child_pid && (WIFEXITED(status) || WIFSIGNALED(status)))
|
||||||
|
pty_child_dead = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called to set up the pty.
|
* Called to set up the pty.
|
||||||
*
|
*
|
||||||
@ -113,6 +132,9 @@ static char *pty_init(char *host, int port, char **realhost, int nodelay)
|
|||||||
exit(127);
|
exit(127);
|
||||||
} else {
|
} else {
|
||||||
close(slavefd);
|
close(slavefd);
|
||||||
|
pty_child_pid = pid;
|
||||||
|
pty_child_dead = FALSE;
|
||||||
|
signal(SIGCHLD, sigchld_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user