From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KQP6X-0004G1-7P for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:09:45 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KQP6W-0004F7-Gh for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:09:44 -0400 Received: from [199.232.76.173] (port=58771 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KQP6W-0004Ev-BT for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:09:44 -0400 Received: from mx1.redhat.com ([66.187.233.31]:36027) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KQP6V-0007GF-Tp for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:09:44 -0400 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m75G9gJr015389 for ; Tue, 5 Aug 2008 12:09:43 -0400 Received: from pobox.stuttgart.redhat.com (pobox.stuttgart.redhat.com [172.16.2.10]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m75G9eGW031511 for ; Tue, 5 Aug 2008 12:09:41 -0400 Received: from zweiblum.travel.kraxel.org (vpn-4-71.str.redhat.com [10.32.4.71]) by pobox.stuttgart.redhat.com (8.13.1/8.13.1) with ESMTP id m75G9dJD017457 for ; Tue, 5 Aug 2008 12:09:40 -0400 Message-ID: <48987B43.4090207@redhat.com> Date: Tue, 05 Aug 2008 18:09:39 +0200 From: Gerd Hoffmann MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------000903070605010008070800" Subject: [Qemu-devel] [PATCH] catch signals Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------000903070605010008070800 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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/ --------------000903070605010008070800 Content-Type: text/plain; name="0004-catch-signals-so-atexit-handlers-are-called-correct.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0004-catch-signals-so-atexit-handlers-are-called-correct.pat"; filename*1="ch" >>From 886775f5229d83d73f3d162b919ea68b386b2a60 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Tue, 5 Aug 2008 17:53:36 +0200 Subject: [PATCH] catch signals, so atexit handlers are called correctly. Signed-off-by: Gerd Hoffmann --- 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 --------------000903070605010008070800--