From: Sebastian Harl Date: Thu, 11 Dec 2014 08:45:41 +0000 (+0100) Subject: sysdb: Make sure to properly reset term attributes. X-Git-Tag: sysdb-0.7.0~112^2~8 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=da5a92e6334c4fc863c4704426666ab768721a67 sysdb: Make sure to properly reset term attributes. Don't record the "old" settings on each call to rawmode since we do that a lot of times. Also, don't use up all atexit handler slots this way. --- diff --git a/src/tools/sysdb/input.c b/src/tools/sysdb/input.c index 55a074c..9ed11ed 100644 --- a/src/tools/sysdb/input.c +++ b/src/tools/sysdb/input.c @@ -92,6 +92,7 @@ sdb_input_t *sysdb_input = NULL; */ static struct termios orig_term_attrs; +static bool have_orig_term_attrs; /* * private helper functions @@ -108,12 +109,15 @@ term_rawmode(void) { struct termios attrs; + if (! have_orig_term_attrs) { + memset(&orig_term_attrs, 0, sizeof(orig_term_attrs)); + tcgetattr(STDIN_FILENO, &orig_term_attrs); + atexit(reset_term_attrs); + have_orig_term_attrs = 1; + } + /* setup terminal to operate in non-canonical mode * and single character input */ - memset(&orig_term_attrs, 0, sizeof(orig_term_attrs)); - tcgetattr(STDIN_FILENO, &orig_term_attrs); - atexit(reset_term_attrs); - memset(&attrs, 0, sizeof(attrs)); tcgetattr(STDIN_FILENO, &attrs); attrs.c_lflag &= (tcflag_t)(~ICANON);