Craig Leres
2016-Apr-22 18:16 UTC
openssh 7.2p2: tty sometimes left in raw mode after a connection timeout
I'm running FreeBSD 9 and openssh 7.2p2: ice 1040 % uname -a FreeBSD ice.ee.lbl.gov 9.3-RELEASE FreeBSD 9.3-RELEASE #1 r21: Fri Mar 4 10:42:36 PST 2016 leres at fun.ee.lbl.gov:/sys/amd64/compile/LBL amd64 ice 1041 % ssh -V OpenSSH_7.2p2, OpenSSL 1.0.2g 1 Mar 2016 Occasionally when a connection times out, ssh leaves my shell in raw mode: packet_write_wait: Connection to UNKNOWN port 0: Broken pipe tcsetattr: Interrupted system call I think the problem is that a signal can interrupt tcsetattr() in leave_raw_mode() causing it to fail with EINTR. When this happens, the terminal is left in raw mode. The attached (untested) patch retries the tcsetattr() if it fails with EINTR. Craig -------------- next part -------------- --- sshtty.c.orig 2016-04-22 11:02:05.000000000 -0700 +++ sshtty.c 2016-04-22 11:12:58.000000000 -0700 @@ -41,6 +41,7 @@ #include <stdio.h> #include <termios.h> #include <pwd.h> +#include <errno.h> #include "sshpty.h" @@ -58,11 +59,14 @@ { if (!_in_raw_mode) return; - if (tcsetattr(fileno(stdin), TCSADRAIN, &_saved_tio) == -1) { + while (tcsetattr(fileno(stdin), TCSADRAIN, &_saved_tio) == -1) { if (!quiet) perror("tcsetattr"); - } else - _in_raw_mode = 0; + if (errno == EINTR) + continue; + return; + } + _in_raw_mode = 0; } void