restore tty echo at exit - vx32 - Local 9vx git repository for patches.
Log
Files
Refs
---
commit 6773153a6a54c531ad60e89e42fbd531b62cb8fa
parent 9ac6ff2beb9d12729f016c4b397293bc4aa8bb61
Author: yiyus 
Date:   Fri,  9 Jul 2010 12:15:50 +0200

restore tty echo at exit

Diffstat:
  src/9vx/tty.c                       |      17 ++++++++++++++++-

1 file changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/src/9vx/tty.c b/src/9vx/tty.c
@@ -26,6 +26,18 @@ uartputs(char *buf, int n)
 }
 
 void
+restoretty(int sig)
+{
+        static struct termios ttmode;
+        
+        if(ttyecho && tcgetattr(0, &ttmode) >= 0){
+                ttmode.c_lflag |= (ECHO|ICANON);
+                tcsetattr(0, TCSANOW, &ttmode);
+        }
+        exit(0);
+}
+
+void
 uartreader(void *v)
 {
         char buf[256];
@@ -33,7 +45,8 @@ uartreader(void *v)
         static struct termios ttmode;
         
         /*
-         * Try to disable host echo. 
+         * Try to disable host echo,
+         * but restore it at exit. 
          * If successful, remember to echo
          * what gets typed ourselves.
          */
@@ -42,6 +55,8 @@ uartreader(void *v)
                 if(tcsetattr(0, TCSANOW, &ttmode) >= 0)
                         ttyecho = 1;
         }
+        signal(SIGINT, restoretty);
+        signal(SIGTERM, restoretty);
         while((n = read(0, buf, sizeof buf)) > 0)
                 echo(buf, n);
 }