From: Ian Jackson Subject: [PATCH v2 1/2] tools/console: reset tty when xenconsole fails Date: Tue, 18 Mar 2014 18:00:27 +0000 Message-ID: <1395165628-1838-1-git-send-email-ian.jackson@eu.citrix.com> References: <21288.35166.479652.469692@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21288.35166.479652.469692@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xensource.com Cc: George Dunlap , Ian Jackson , Ian Campbell , M A Young List-Id: xen-devel@lists.xenproject.org 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 Signed-off-by: Ian Jackson CC: M A Young CC: Ian Campbell Acked-by: George Dunlap Acked-by: Ian Campbell --- v2: Fix whitespace error (reintroduce hard tab) Fix commit message not to claim ignorance about root cause --- tools/console/client/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/console/client/main.c b/tools/console/client/main.c index eb6a1a9..7ce4f24 100644 --- a/tools/console/client/main.c +++ b/tools/console/client/main.c @@ -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); -- 1.7.10.4