From d37c2d8198de28cc4076c560dff9a94f8452fe7c Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 14 Oct 2002 08:56:55 +0000 Subject: [PATCH] Various faffs in the pty allocation process to get controlling terminals right. Irritatingly this was working when run from another [xsp]term but not when run from my GNOME panel. I think it's now more robust. git-svn-id: svn://svn.tartarus.org/sgt/putty@2041 cda61777-01e9-0310-a592-d414129be87e --- unix/pty.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/unix/pty.c b/unix/pty.c index e5b6ad54..8a3d06be 100644 --- a/unix/pty.c +++ b/unix/pty.c @@ -36,7 +36,7 @@ static char *pty_init(char *host, int port, char **realhost, int nodelay) { int slavefd; char name[FILENAME_MAX]; - pid_t pid; + pid_t pid, pgrp; pty_master_fd = open("/dev/ptmx", O_RDWR); @@ -58,12 +58,6 @@ static char *pty_init(char *host, int port, char **realhost, int nodelay) name[FILENAME_MAX-1] = '\0'; strncpy(name, ptsname(pty_master_fd), FILENAME_MAX-1); - slavefd = open(name, O_RDWR); - if (slavefd < 0) { - perror("slave pty: open"); - exit(1); - } - /* * Fork and execute the command. */ @@ -78,6 +72,13 @@ static char *pty_init(char *host, int port, char **realhost, int nodelay) /* * We are the child. */ + + slavefd = open(name, O_RDWR); + if (slavefd < 0) { + perror("slave pty: open"); + exit(1); + } + close(pty_master_fd); close(0); close(1); @@ -87,8 +88,12 @@ static char *pty_init(char *host, int port, char **realhost, int nodelay) dup2(slavefd, 1); dup2(slavefd, 2); setsid(); + ioctl(slavefd, TIOCSCTTY, 1); + pgrp = getpid(); + tcsetpgrp(slavefd, pgrp); + setpgrp(); + close(open(name, O_WRONLY, 0)); setpgrp(); - tcsetpgrp(slavefd, getpgrp()); /* Close everything _else_, for tidiness. */ for (i = 3; i < 1024; i++) close(i); -- 2.11.0