Commit 5b08fc106d3146ddc1447d82d4770fc402fc363b
1 parent
6f382b5e
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 <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5055 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
3 changed files
with
28 additions
and
10 deletions
curses.c
@@ -350,8 +350,6 @@ void curses_display_init(DisplayState *ds, int full_screen) | @@ -350,8 +350,6 @@ void curses_display_init(DisplayState *ds, int full_screen) | ||
350 | atexit(curses_atexit); | 350 | atexit(curses_atexit); |
351 | 351 | ||
352 | #ifndef _WIN32 | 352 | #ifndef _WIN32 |
353 | - signal(SIGINT, SIG_DFL); | ||
354 | - signal(SIGQUIT, SIG_DFL); | ||
355 | #if defined(SIGWINCH) && defined(KEY_RESIZE) | 353 | #if defined(SIGWINCH) && defined(KEY_RESIZE) |
356 | /* some curses implementations provide a handler, but we | 354 | /* some curses implementations provide a handler, but we |
357 | * want to be sure this is handled regardless of the library */ | 355 | * want to be sure this is handled regardless of the library */ |
sdl.c
@@ -476,10 +476,8 @@ static void sdl_refresh(DisplayState *ds) | @@ -476,10 +476,8 @@ static void sdl_refresh(DisplayState *ds) | ||
476 | sdl_process_key(&ev->key); | 476 | sdl_process_key(&ev->key); |
477 | break; | 477 | break; |
478 | case SDL_QUIT: | 478 | case SDL_QUIT: |
479 | - if (!no_quit) { | 479 | + if (!no_quit) |
480 | qemu_system_shutdown_request(); | 480 | qemu_system_shutdown_request(); |
481 | - vm_start(); /* In case we're paused */ | ||
482 | - } | ||
483 | break; | 481 | break; |
484 | case SDL_MOUSEMOTION: | 482 | case SDL_MOUSEMOTION: |
485 | if (gui_grab || kbd_mouse_is_absolute() || | 483 | if (gui_grab || kbd_mouse_is_absolute() || |
@@ -636,11 +634,6 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) | @@ -636,11 +634,6 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) | ||
636 | fprintf(stderr, "Could not initialize SDL - exiting\n"); | 634 | fprintf(stderr, "Could not initialize SDL - exiting\n"); |
637 | exit(1); | 635 | exit(1); |
638 | } | 636 | } |
639 | -#ifndef _WIN32 | ||
640 | - /* NOTE: we still want Ctrl-C to work, so we undo the SDL redirections */ | ||
641 | - signal(SIGINT, SIG_DFL); | ||
642 | - signal(SIGQUIT, SIG_DFL); | ||
643 | -#endif | ||
644 | 637 | ||
645 | ds->dpy_update = sdl_update; | 638 | ds->dpy_update = sdl_update; |
646 | ds->dpy_resize = sdl_resize; | 639 | ds->dpy_resize = sdl_resize; |
vl.c
@@ -7621,6 +7621,8 @@ static int main_loop(void) | @@ -7621,6 +7621,8 @@ static int main_loop(void) | ||
7621 | timeout = 0; | 7621 | timeout = 0; |
7622 | } | 7622 | } |
7623 | } else { | 7623 | } else { |
7624 | + if (shutdown_requested) | ||
7625 | + break; | ||
7624 | timeout = 10; | 7626 | timeout = 10; |
7625 | } | 7627 | } |
7626 | #ifdef CONFIG_PROFILER | 7628 | #ifdef CONFIG_PROFILER |
@@ -8185,6 +8187,26 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type) | @@ -8185,6 +8187,26 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type) | ||
8185 | 8187 | ||
8186 | #define MAX_NET_CLIENTS 32 | 8188 | #define MAX_NET_CLIENTS 32 |
8187 | 8189 | ||
8190 | +#ifndef _WIN32 | ||
8191 | + | ||
8192 | +static void termsig_handler(int signal) | ||
8193 | +{ | ||
8194 | + qemu_system_shutdown_request(); | ||
8195 | +} | ||
8196 | + | ||
8197 | +void termsig_setup(void) | ||
8198 | +{ | ||
8199 | + struct sigaction act; | ||
8200 | + | ||
8201 | + memset(&act, 0, sizeof(act)); | ||
8202 | + act.sa_handler = termsig_handler; | ||
8203 | + sigaction(SIGINT, &act, NULL); | ||
8204 | + sigaction(SIGHUP, &act, NULL); | ||
8205 | + sigaction(SIGTERM, &act, NULL); | ||
8206 | +} | ||
8207 | + | ||
8208 | +#endif | ||
8209 | + | ||
8188 | int main(int argc, char **argv) | 8210 | int main(int argc, char **argv) |
8189 | { | 8211 | { |
8190 | #ifdef CONFIG_GDBSTUB | 8212 | #ifdef CONFIG_GDBSTUB |
@@ -9073,6 +9095,11 @@ int main(int argc, char **argv) | @@ -9073,6 +9095,11 @@ int main(int argc, char **argv) | ||
9073 | #endif | 9095 | #endif |
9074 | } | 9096 | } |
9075 | 9097 | ||
9098 | +#ifndef _WIN32 | ||
9099 | + /* must be after terminal init, SDL library changes signal handlers */ | ||
9100 | + termsig_setup(); | ||
9101 | +#endif | ||
9102 | + | ||
9076 | /* Maintain compatibility with multiple stdio monitors */ | 9103 | /* Maintain compatibility with multiple stdio monitors */ |
9077 | if (!strcmp(monitor_device,"stdio")) { | 9104 | if (!strcmp(monitor_device,"stdio")) { |
9078 | for (i = 0; i < MAX_SERIAL_PORTS; i++) { | 9105 | for (i = 0; i < MAX_SERIAL_PORTS; i++) { |