Code

sysdb: Make sure to properly reset term attributes.
authorSebastian Harl <sh@tokkee.org>
Thu, 11 Dec 2014 08:45:41 +0000 (09:45 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 11 Dec 2014 08:45:41 +0000 (09:45 +0100)
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

index 55a074cd3863f8a39fa947a7f96cba2d8822488f..9ed11eddd0e26309fab0bbda7333495ae86bd37c 100644 (file)
@@ -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);