diff -r 2cc9ec0cf061 i386-dm/helper2.c --- a/i386-dm/helper2.c Fri Apr 30 17:41:45 2010 +0100 +++ b/i386-dm/helper2.c Wed May 05 10:57:33 2010 +0800 @@ -550,12 +550,27 @@ int xen_pause_requested; +int finish_work_shutdown(int timeout) +{ + extern int shutdown_requested; + extern int connected_disks; + if (shutdown_requested){ + while(connected_disks > 0 && timeout > 0){ + main_loop_wait(1); + timeout--; + } + } + raise(SIGKILL); + return 1; +} + int main_loop(void) { CPUState *env = cpu_single_env; int evtchn_fd = xce_handle == -1 ? -1 : xc_evtchn_fd(xce_handle); char *qemu_file; fd_set fds; + extern int shutdown_requested; main_loop_prepare(); @@ -571,9 +586,12 @@ qemu_set_fd_handler(xenstore_fd(), xenstore_process_event, NULL, NULL); while (1) { - while (!(vm_running && xen_pause_requested)) + while (!(vm_running && xen_pause_requested)){ + if (shutdown_requested) + finish_work_shutdown(2000); //timeout 5s /* Wait up to 10 msec. */ main_loop_wait(10); + } fprintf(logfile, "device model saving state\n"); @@ -595,6 +613,9 @@ FD_SET(xenstore_fd(), &fds); if (select(xenstore_fd() + 1, &fds, NULL, NULL, NULL) > 0) xenstore_process_event(NULL); + if (shutdown_requested) + finish_work_shutdown(2000); + } xenstore_record_dm_state("running"); diff -r 2cc9ec0cf061 vl.c --- a/vl.c Fri Apr 30 17:41:45 2010 +0100 +++ b/vl.c Wed May 05 10:57:33 2010 +0800 @@ -3614,7 +3614,7 @@ static QEMUResetEntry *first_reset_entry; static int reset_requested; -static int shutdown_requested; +int shutdown_requested; static int powerdown_requested; int qemu_shutdown_requested(void) @@ -4699,9 +4699,11 @@ memset(&act, 0, sizeof(act)); act.sa_handler = termsig_handler; +#ifndef CONFIG_DM sigaction(SIGINT, &act, NULL); + sigaction(SIGTERM, &act, NULL); +#endif sigaction(SIGHUP, &act, NULL); - sigaction(SIGTERM, &act, NULL); } #endif @@ -5851,11 +5853,9 @@ register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL); #ifndef _WIN32 -#ifndef CONFIG_DM /* must be after terminal init, SDL library changes signal handlers */ termsig_setup(); #endif -#endif /* Maintain compatibility with multiple stdio monitors */ if (!strcmp(monitor_device,"stdio")) {