public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Anton Vorontsov <cbouatmailru@gmail.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] kvm tools: Fix broken terminal when kvm exits because of a signal
Date: Fri, 17 Jun 2011 20:10:46 +0400	[thread overview]
Message-ID: <20110617161046.GA13705@oksana.dev.rtsoft.ru> (raw)

Issuing 'killall kvm' leaves the terminal on which kvm was running in
a broken state. This is because atexit(3) handlers are not called if
a process terminates because of a signal.

Installing a proper handler for the TERM signal fixes the issue.

p.s. The rest of the kvm tools use signal(2), and not sigaction(2), so
     I continue the tradition.

Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
---
 tools/kvm/term.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/term.c b/tools/kvm/term.c
index 689d52d..9947223 100644
--- a/tools/kvm/term.c
+++ b/tools/kvm/term.c
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/uio.h>
+#include <signal.h>
 
 #include "kvm/read-write.h"
 #include "kvm/term.h"
@@ -102,6 +103,13 @@ static void term_cleanup(void)
 	tcsetattr(STDIN_FILENO, TCSANOW, &orig_term);
 }
 
+static void term_sig_cleanup(int sig)
+{
+	term_cleanup();
+	signal(sig, SIG_DFL);
+	raise(sig);
+}
+
 void term_init(void)
 {
 	struct termios term;
@@ -113,5 +121,6 @@ void term_init(void)
 	term.c_lflag &= ~(ICANON | ECHO | ISIG);
 	tcsetattr(STDIN_FILENO, TCSANOW, &term);
 
+	signal(SIGTERM, term_sig_cleanup);
 	atexit(term_cleanup);
 }
-- 
1.7.5.3

                 reply	other threads:[~2011-06-17 16:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110617161046.GA13705@oksana.dev.rtsoft.ru \
    --to=cbouatmailru@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox