--- rxvt-unicode/src/ptytty.C 2006/10/03 11:21:33 1.63 +++ rxvt-unicode/src/ptytty.C 2007/12/11 21:49:12 1.68 @@ -65,7 +65,7 @@ * GET PSEUDO TELETYPE - MASTER AND SLAVE * * ------------------------------------------------------------------------- */ /* - * Returns pty file descriptor, or -1 on failure + * Returns pty file descriptor, or -1 on failure * If successful, ttydev is set to the name of the slave device. * fd_tty _may_ also be set to an open fd to the slave device */ @@ -88,7 +88,8 @@ { if (grantpt (pfd) == 0 /* change slave permissions */ && unlockpt (pfd) == 0) - { /* slave now unlocked */ + { + /* slave now unlocked */ *ttydev = strdup (ptsname (pfd)); /* get slave's name */ return pfd; } @@ -106,13 +107,12 @@ { int pfd; int res; - char tty_name[32]; - - res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); + + res = openpty (&pfd, fd_tty, NULL, NULL, NULL); if (res != -1) { - *ttydev = strdup (tty_name); + *ttydev = strdup (ttyname (*fd_tty)); return pfd; } @@ -125,11 +125,14 @@ get_pty (int *fd_tty, char **ttydev) { int pfd; + char *slave; - *ttydev = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0); + slave = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0); - if (*ttydev != NULL) + if (slave != NULL) { + *ttydev = strdup (slave); return pfd; + } return -1; } @@ -208,7 +211,7 @@ /*----------------------------------------------------------------------*/ /* - * Returns tty file descriptor, or -1 on failure + * Returns tty file descriptor, or -1 on failure */ static int get_tty (char *ttydev) @@ -223,6 +226,8 @@ static int control_tty (int fd_tty) { + int fd; + setsid (); #if defined(HAVE_DEV_PTMX) && defined(I_PUSH) @@ -253,9 +258,15 @@ } #endif +#ifdef TIOCSCTTY ioctl (fd_tty, TIOCSCTTY, NULL); +#else + fd = open (ttyname (fd_tty), O_RDWR); + if (fd >= 0) + close (fd); +#endif - int fd = open ("/dev/tty", O_WRONLY); + fd = open ("/dev/tty", O_WRONLY); if (fd < 0) return -1; /* fatal */ @@ -317,12 +328,13 @@ struct group *gr = getgrnam ("tty"); if (gr) - { /* change group ownership of tty to "tty" */ + { + /* change group ownership of tty to "tty" */ mode = S_IRUSR | S_IWUSR | S_IWGRP; gid = gr->gr_gid; } else -#endif /* TTY_GID_SUPPORT */ +#endif /* TTY_GID_SUPPORT */ { mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; gid = 0;