]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Various faffs in the pty allocation process to get controlling
authorSimon Tatham <anakin@pobox.com>
Mon, 14 Oct 2002 08:56:55 +0000 (08:56 +0000)
committerSimon Tatham <anakin@pobox.com>
Mon, 14 Oct 2002 08:56:55 +0000 (08:56 +0000)
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.

[originally from svn r2041]

unix/pty.c

index e5b6ad54a473c99c47a476c9718a055a6316bbac..8a3d06be9eadfd4cca10c165e2ce33be876df6e5 100644 (file)
@@ -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);