From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KWGRy-0004Tz-AE for qemu-devel@nongnu.org; Thu, 21 Aug 2008 16:08:06 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KWGRx-0004Rq-Cn for qemu-devel@nongnu.org; Thu, 21 Aug 2008 16:08:05 -0400 Received: from [199.232.76.173] (port=55676 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KWGRw-0004R7-SQ for qemu-devel@nongnu.org; Thu, 21 Aug 2008 16:08:04 -0400 Received: from savannah.gnu.org ([199.232.41.3]:35351 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KWGRw-0005bj-CC for qemu-devel@nongnu.org; Thu, 21 Aug 2008 16:08:04 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1KWGRv-0004PW-OS for qemu-devel@nongnu.org; Thu, 21 Aug 2008 20:08:03 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1KWGRv-0004PS-DQ for qemu-devel@nongnu.org; Thu, 21 Aug 2008 20:08:03 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 21 Aug 2008 20:08:03 +0000 Subject: [Qemu-devel] [5055] Handle terminating signals (Gerd Hoffmann) 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 Revision: 5055 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5055 Author: aliguori Date: 2008-08-21 20:08:03 +0000 (Thu, 21 Aug 2008) Log Message: ----------- Handle terminating signals (Gerd Hoffmann) This patch makes qemu handle signals better. It sets the request_shutdown flag, making the main_loop exit and qemu taking the usual exit route, with atexit handlers being called and so on, instead of qemu just being killed by the signal. To avoid calling vm_start() from the signal handler main_loop() got an additional check so qemu_system_shutdown_request() works even when the vm is in stopped state. Signed-off-by: Gerd Hoffmann Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/curses.c trunk/sdl.c trunk/vl.c Modified: trunk/curses.c =================================================================== --- trunk/curses.c 2008-08-21 19:33:09 UTC (rev 5054) +++ trunk/curses.c 2008-08-21 20:08:03 UTC (rev 5055) @@ -350,8 +350,6 @@ 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 */ Modified: trunk/sdl.c =================================================================== --- trunk/sdl.c 2008-08-21 19:33:09 UTC (rev 5054) +++ trunk/sdl.c 2008-08-21 20:08:03 UTC (rev 5055) @@ -476,10 +476,8 @@ sdl_process_key(&ev->key); break; case SDL_QUIT: - if (!no_quit) { + if (!no_quit) qemu_system_shutdown_request(); - vm_start(); /* In case we're paused */ - } break; case SDL_MOUSEMOTION: if (gui_grab || kbd_mouse_is_absolute() || @@ -636,11 +634,6 @@ 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; Modified: trunk/vl.c =================================================================== --- trunk/vl.c 2008-08-21 19:33:09 UTC (rev 5054) +++ trunk/vl.c 2008-08-21 20:08:03 UTC (rev 5055) @@ -7621,6 +7621,8 @@ timeout = 0; } } else { + if (shutdown_requested) + break; timeout = 10; } #ifdef CONFIG_PROFILER @@ -8185,6 +8187,26 @@ #define MAX_NET_CLIENTS 32 +#ifndef _WIN32 + +static void termsig_handler(int signal) +{ + qemu_system_shutdown_request(); +} + +void termsig_setup(void) +{ + struct sigaction act; + + memset(&act, 0, sizeof(act)); + act.sa_handler = termsig_handler; + sigaction(SIGINT, &act, NULL); + sigaction(SIGHUP, &act, NULL); + sigaction(SIGTERM, &act, NULL); +} + +#endif + int main(int argc, char **argv) { #ifdef CONFIG_GDBSTUB @@ -9073,6 +9095,11 @@ #endif } +#ifndef _WIN32 + /* must be after terminal init, SDL library changes signal handlers */ + termsig_setup(); +#endif + /* Maintain compatibility with multiple stdio monitors */ if (!strcmp(monitor_device,"stdio")) { for (i = 0; i < MAX_SERIAL_PORTS; i++) {