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>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
#include <stdio.h>
#include <unistd.h>
#include <sys/uio.h>
+#include <signal.h>
#include "kvm/read-write.h"
#include "kvm/term.h"
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;
term.c_lflag &= ~(ICANON | ECHO | ISIG);
tcsetattr(STDIN_FILENO, TCSANOW, &term);
+ signal(SIGTERM, term_sig_cleanup);
atexit(term_cleanup);
}