--- rxvt-unicode/src/ptytty.C 2006/01/01 05:08:41 1.25 +++ rxvt-unicode/src/ptytty.C 2006/01/04 03:02:01 1.28 @@ -76,11 +76,11 @@ int pfd; #ifdef PTYS_ARE_OPENPTY - char tty_name[sizeof "/dev/pts/?????\0"]; + char tty_name[sizeof "/dev/pts/????\0"]; - rxvt_privileges (RESTORE); + rxvt_privileges(RESTORE); int res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); - rxvt_privileges (IGNORE); + rxvt_privileges(IGNORE); if (res != -1) { @@ -96,7 +96,6 @@ #endif #ifdef PTYS_ARE_GETPTY - char *ptydev; while ((ptydev = getpty ()) != NULL) @@ -340,21 +339,21 @@ void rxvt_ptytty::privileges (rxvt_privaction action) { - if (pty < 0) + if (!name || !*name) return; rxvt_privileges (RESTORE); if (action == SAVE) { - //next_tty_action = RESTORE; # ifndef RESET_TTY_TO_COMMON_DEFAULTS /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ if (lstat (name, &savestat) < 0) /* you lose out */ - ;//next_tty_action = IGNORE; + ; else # endif { + saved = true; chown (name, getuid (), ttyconf.gid); /* fail silently */ chmod (name, ttyconf.mode); # ifdef HAVE_REVOKE @@ -364,10 +363,12 @@ } else { /* action == RESTORE */ - //next_tty_action = IGNORE; # ifndef RESET_TTY_TO_COMMON_DEFAULTS - chmod (name, savestat.st_mode); - chown (name, savestat.st_uid, savestat.st_gid); + if (saved) + { + chmod (name, savestat.st_mode); + chown (name, savestat.st_uid, savestat.st_gid); + } # else chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); chown (name, 0, 0); @@ -383,6 +384,9 @@ { pty = tty = -1; name = 0; +#ifndef NO_SETOWNER_TTYDEV + saved = false; +#endif } rxvt_ptytty::~rxvt_ptytty () @@ -402,8 +406,7 @@ rxvt_ptytty::put () { #ifndef NO_SETOWNER_TTYDEV - if (tty >= 0) - privileges (RESTORE); + privileges (RESTORE); #endif if (pty >= 0) close (pty);