vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

commit 9ed785bcfd6fb893a6c55a00e2b82e208028af4c
parent 00609a358ceb048d8a8b74df8369426e49468552
Author: yiyus <none@none>
Date:   Fri,  9 Jul 2010 22:46:55 +0200

do not assume that ECHO|ICANON is the previous tty state

Diffstat:
src/9vx/tty.c | 15++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/9vx/tty.c b/src/9vx/tty.c @@ -13,6 +13,7 @@ static int ttyprint = 0; static int ttyecho = 0; +static struct termios ttprevmode; /* * Normal prints and console output go to standard output. @@ -28,11 +29,9 @@ uartputs(char *buf, int n) void restoretty(void) { - static struct termios ttmode; - - if(ttyecho && tcgetattr(0, &ttmode) >= 0){ - ttmode.c_lflag |= (ECHO|ICANON); - tcsetattr(0, TCSANOW, &ttmode); + if(ttyecho && tcsetattr(0, TCSANOW, &ttprevmode) < 0){ + ttyecho = 0; + panic("could not restore previous tty mode"); } } @@ -51,11 +50,13 @@ uartreader(void *v) static struct termios ttmode; /* - * Try to disable host echo, - * but restore it at exit. + * Try to disable host echo, save + * current state to restore it at exit. * If successful, remember to echo * what gets typed ourselves. */ + if(tcgetattr(0, &ttprevmode) < 0) + panic("could not read tty current mode"); if(tcgetattr(0, &ttmode) >= 0){ ttmode.c_lflag &= ~(ECHO|ICANON); if(tcsetattr(0, TCSANOW, &ttmode) >= 0)