From da5a92e6334c4fc863c4704426666ab768721a67 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Thu, 11 Dec 2014 09:45:41 +0100 Subject: [PATCH] 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. --- src/tools/sysdb/input.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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); -- 2.30.2