# HG changeset patch # User Mikael Berthe # Date 1144355806 -7200 # Node ID 1fa93cc6f5e3d5ee2f846dc6369d7147e63de7cc # Parent 7f10b84ba7fcbad0b7650d8e0503888c63fcc021 Correctly restore term settings when interrupting the password query diff -r 7f10b84ba7fc -r 1fa93cc6f5e3 mcabber/src/main.c --- 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++) ;