tools/console: reset tty when xenconsole fails
authorIan Jackson <ian.jackson@eu.citrix.com>
Mon, 24 Feb 2014 15:16:19 +0000 (15:16 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Wed, 19 Mar 2014 13:37:19 +0000 (13:37 +0000)
If xenconsole (the client program) fails, it calls err.  This would
previously neglect to reset the user's terminal to sanity.  Use atexit
to do so.

This routinely happens in Xen 4.4 RC5 with pygrub because libxl
writes the value "" to the tty xenstore key when using xenconsole.
After this patch this just results in a harmless error message.

Reported-by: M A Young <m.a.young@durham.ac.uk>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: M A Young <m.a.young@durham.ac.uk>
CC: Ian Campbell <Ian.Campbell@citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
v2: Fix whitespace error (reintroduce hard tab)
    Fix commit message not to claim ignorance about root cause

tools/console/client/main.c

index eb6a1a93151e05af8c95b26849c5152d70666f84..7ce4f24aba7a9e0388fd6317685eec11bd2c2b1d 100644 (file)
@@ -257,6 +257,13 @@ typedef enum {
        CONSOLE_SERIAL,
 } console_type;
 
+static struct termios stdin_old_attr;
+
+static void restore_term_stdin(void)
+{
+       restore_term(STDIN_FILENO, &stdin_old_attr);
+}
+
 int main(int argc, char **argv)
 {
        struct termios attr;
@@ -383,9 +390,9 @@ int main(int argc, char **argv)
        }
 
        init_term(spty, &attr);
-       init_term(STDIN_FILENO, &attr);
+       init_term(STDIN_FILENO, &stdin_old_attr);
+       atexit(restore_term_stdin); /* if this fails, oh dear */
        console_loop(spty, xs, path);
-       restore_term(STDIN_FILENO, &attr);
 
        free(path);
        free(dom_path);