зеркало из https://github.com/github/putty.git
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:
Родитель
b3072e227e
Коммит
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)
|
||||
{
|
||||
/* 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();
|
||||
return TRUE;
|
||||
|
|
22
unix/pty.c
22
unix/pty.c
|
@ -6,8 +6,11 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "putty.h"
|
||||
|
@ -20,10 +23,26 @@
|
|||
#endif
|
||||
|
||||
int pty_master_fd;
|
||||
static int pty_child_pid;
|
||||
static sig_atomic_t pty_child_dead;
|
||||
char **pty_argv;
|
||||
|
||||
int pty_child_is_dead(void)
|
||||
{
|
||||
return pty_child_dead;
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
|
@ -113,6 +132,9 @@ static char *pty_init(char *host, int port, char **realhost, int nodelay)
|
|||
exit(127);
|
||||
} else {
|
||||
close(slavefd);
|
||||
pty_child_pid = pid;
|
||||
pty_child_dead = FALSE;
|
||||
signal(SIGCHLD, sigchld_handler);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
Загрузка…
Ссылка в новой задаче