From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] catch signals
Date: Tue, 05 Aug 2008 18:09:39 +0200 [thread overview]
Message-ID: <48987B43.4090207@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 310 bytes --]
Hi,
This patch adds a signal handler to qemu, so fatal signals don't kill
off qemu. Instead a shutdown request is issued, like it is done when
you close the SDL window. qemu cleans up nicely then, cespecially it
calls all atexit handlers.
please apply,
Gerd
--
http://kraxel.fedorapeople.org/xenner/
[-- Attachment #2: 0004-catch-signals-so-atexit-handlers-are-called-correct.patch --]
[-- Type: text/plain, Size: 2772 bytes --]
>From 886775f5229d83d73f3d162b919ea68b386b2a60 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Tue, 5 Aug 2008 17:53:36 +0200
Subject: [PATCH] catch signals, so atexit handlers are called correctly.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
curses.c | 2 --
sdl.c | 5 -----
vl.c | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 7 deletions(-)
diff --git a/curses.c b/curses.c
index 87aa9b3..03580fb 100644
--- a/curses.c
+++ b/curses.c
@@ -346,8 +346,6 @@ void curses_display_init(DisplayState *ds, int full_screen)
atexit(curses_atexit);
#ifndef _WIN32
- signal(SIGINT, SIG_DFL);
- signal(SIGQUIT, SIG_DFL);
#if defined(SIGWINCH) && defined(KEY_RESIZE)
/* some curses implementations provide a handler, but we
* want to be sure this is handled regardless of the library */
diff --git a/sdl.c b/sdl.c
index 0edc4a0..9ac5725 100644
--- a/sdl.c
+++ b/sdl.c
@@ -636,11 +636,6 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
fprintf(stderr, "Could not initialize SDL - exiting\n");
exit(1);
}
-#ifndef _WIN32
- /* NOTE: we still want Ctrl-C to work, so we undo the SDL redirections */
- signal(SIGINT, SIG_DFL);
- signal(SIGQUIT, SIG_DFL);
-#endif
ds->dpy_update = sdl_update;
ds->dpy_resize = sdl_resize;
diff --git a/vl.c b/vl.c
index e929370..c70b984 100644
--- a/vl.c
+++ b/vl.c
@@ -8141,6 +8141,40 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
#define MAX_NET_CLIENTS 32
+#ifndef _WIN32
+static void termsig_handler(int signal)
+{
+ switch (signal) {
+ case SIGSEGV:
+ case SIGBUS:
+ /* returning from signal handler most likely isn't going to work */
+ fprintf(stderr, "qemu: got signal %d (%s), taking emergency exit\n",
+ signal, strsignal(signal));
+ exit(1);
+ break;
+ default:
+ qemu_system_shutdown_request();
+ vm_start(); /* In case we're paused */
+ break;
+ }
+}
+
+static void termsig_setup(void)
+{
+ struct sigaction act;
+
+ memset(&act, 0, sizeof(act));
+ act.sa_flags = SA_RESETHAND;
+ act.sa_handler = termsig_handler;
+
+ sigaction(SIGINT, &act, NULL);
+ sigaction(SIGTERM, &act, NULL);
+ sigaction(SIGQUIT, &act, NULL);
+ sigaction(SIGSEGV, &act, NULL);
+ sigaction(SIGBUS, &act, NULL);
+}
+#endif
+
int main(int argc, char **argv)
{
#ifdef CONFIG_GDBSTUB
@@ -9031,6 +9065,11 @@ int main(int argc, char **argv)
#endif
}
+#ifndef _WIN32
+ /* must be after terminal init, SDL changes signal handlers */
+ termsig_setup();
+#endif
+
/* Maintain compatibility with multiple stdio monitors */
has_monitor = 0;
--
1.5.5.1
next reply other threads:[~2008-08-05 16:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-05 16:09 Gerd Hoffmann [this message]
2008-08-05 16:29 ` [Qemu-devel] [PATCH] catch signals Samuel Thibault
2008-08-06 9:11 ` Gerd Hoffmann
2008-08-05 16:35 ` Daniel P. Berrange
2008-08-05 16:53 ` Samuel Thibault
2008-08-05 17:00 ` Daniel P. Berrange
2008-08-05 18:39 ` Jamie Lokier
2008-08-06 9:20 ` Gerd Hoffmann
2008-08-06 9:48 ` Daniel P. Berrange
2008-08-11 16:50 ` Ian Jackson
2008-08-11 19:43 ` Gerd Hoffmann
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=48987B43.4090207@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).