Hello, openssh-3.0.1p1 appears to transmit and parse tty modes correctly, but later in the code it uses vhangup() to close all tty references and reset the tty to default modes. I don't think that vhangup() should be needed on Unix98 ptys, possibly not even on BSD ptys, and I am probably wrong, so please tell me where. Of course vhangup() clears all tty modes, so you need to save them before and restore them to the newly opened tty afterwards. This is on Linux 2.4.14, but the problem looks quite portable to me for all systems that have vhangup(). This patch shows my solution, but it's only a hack to me until I know why vhangup() is needed: --- sshpty.c.orig Tue Nov 27 02:32:50 2001 +++ sshpty.c Tue Nov 27 02:33:45 2001 @@ -252,6 +252,7 @@ int fd; #ifdef USE_VHANGUP void *old; + struct termios tio; #endif /* USE_VHANGUP */ #ifdef _CRAY @@ -310,6 +311,7 @@ #endif /* HAVE_NEWS4 */ #ifdef USE_VHANGUP old = mysignal(SIGHUP, SIG_IGN); + tcgetattr(*ttyfd,&tio); vhangup(); mysignal(SIGHUP, old); #endif /* USE_VHANGUP */ @@ -320,6 +322,7 @@ #ifdef USE_VHANGUP close(*ttyfd); *ttyfd = fd; + tcsetattr(*ttyfd,TCSANOW,&tio); #else /* USE_VHANGUP */ close(fd); #endif /* USE_VHANGUP */ I am not subscribed to the list, so please cc: to me. Michael
On 27 Nov 2001 michael at moria.de wrote: :openssh-3.0.1p1 appears to transmit and parse tty modes correctly, :but later in the code it uses vhangup() to close all tty references and :reset the tty to default modes. I don't think that vhangup() should be :needed on Unix98 ptys, possibly not even on BSD ptys, and I am probably :wrong, so please tell me where. Of course vhangup() clears all tty modes, :so you need to save them before and restore them to the newly opened :tty afterwards. This is on Linux 2.4.14, but the problem looks quite :portable to me for all systems that have vhangup(). : :This patch shows my solution, but it's only a hack to me until I know :why vhangup() is needed: thanks. as i recall this has come up before. i would really like to see someone with deep linux pty knowledge investigate this, identify the problems, and propose a solution. i think the archives may contain other proposed fixes.
> thanks. as i recall this has come up before. i would really like to see > someone with deep linux pty knowledge investigate this, identify the > problems, and propose a solution. i think the archives may contain other > proposed fixes.By now I think I know why vhangup() is needed: After opening the master, someone else may have opened the slave before sshd does. vhangup() gets rid of those handles and if tty ownership is set before, other users can't reopen the slave again. As I suspected, my patch was just a hack. The real problem is in session.c, around line 1662: The modes are set before ownership is changed, but instead ownership should be changed, then vhangup() should be used and _then_ modes should be set. This should not only concern Linux, but all systems that support vhangup(), which is the majority of all Unices. Michael