changeset 789:1fa93cc6f5e3

Correctly restore term settings when interrupting the password query
author Mikael Berthe <mikael@lilotux.net>
date Thu, 06 Apr 2006 22:36:46 +0200
parents 7f10b84ba7fc
children 5d4ad1d77da4
files mcabber/src/main.c
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/main.c	Wed Apr 05 21:47:16 2006 +0200
+++ b/mcabber/src/main.c	Thu Apr 06 22:36:46 2006 +0200
@@ -46,6 +46,8 @@
 #endif
 
 
+static struct termios *backup_termios;
+
 char *mcabber_version(void)
 {
   char *ver;
@@ -124,6 +126,11 @@
 {
   jb_disconnect();
   scr_TerminateCurses();
+
+  // Restore term settings, if needed.
+  if (backup_termios)
+    tcsetattr(fileno(stdin), TCSAFLUSH, backup_termios);
+
   if (msg)
     fprintf(stderr, "%s\n", msg);
   printf("Bye!\n");
@@ -167,6 +174,8 @@
 
   /* Turn echoing off and fail if we can't. */
   if (tcgetattr(fileno(stdin), &orig) != 0) return;
+  backup_termios = &orig;
+
   new = orig;
   new.c_lflag &= ~ECHO;
   if (tcsetattr(fileno(stdin), TCSAFLUSH, &new) != 0) return;
@@ -178,6 +187,7 @@
   /* Restore terminal. */
   tcsetattr(fileno(stdin), TCSAFLUSH, &orig);
   printf("\n");
+  backup_termios = NULL;
 
   for (p = (char*)password; *p; p++)
     ;