From: Jan K. <jan...@si...> - 2008-01-21 10:00:40
|
Hi Guido, [posting via gmane sucks, just re-enabled mail delivery in this account...] Guido Guenther wrote: > Hi Jan, > On Sat, Jan 19, 2008 at 04:40:06PM +0100, Jan Kiszka wrote: >> What about additionally listening on signals? If you run qemu from the >> console, you can then just press ctrl-c to shut the guest down (instead > Catching ctrl-c sounds like a good idea but "ctrl-c, ctrl-c" should > probably kill qemu then, since the machine might have no acpid running - > in that case hitting ctrl-c would have no effect. Good idea. > >> of killing it that way). The same happens on host shutdown (if the guest >> is faster than the host's grace period before SIGKILL...). > >> + signal(SIGINT, qemu_powerdown_sighand); >> + signal(SIGTERM, qemu_powerdown_sighand); > We shouldn't catch SIGTERM here since libvirt uses it for > domainDestroy() (in contrast to domainShutdown() which uses > system_powerdown). Something like this? I also included the SDL window this time, and at least I like it this way now :-> Jan -- Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux --- qemu/sdl.c | 2 +- qemu/sysemu.h | 2 +- qemu/vl.c | 21 ++++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) Index: b/qemu/vl.c =================================================================== --- a/qemu/vl.c +++ b/qemu/vl.c @@ -7653,9 +7653,21 @@ void qemu_system_shutdown_request(void) cpu_interrupt(cpu_single_env, CPU_INTERRUPT_EXIT); } +/* more than one requests within 2 s => hard powerdown */ +#define HARD_POWERDOWN_WINDOW 2 + void qemu_system_powerdown_request(void) { - powerdown_requested = 1; + static time_t last_request; + time_t now, delta; + + now = time(NULL); + delta = now-last_request; + last_request = now; + if (delta < 0 || delta > HARD_POWERDOWN_WINDOW) + powerdown_requested = 1; + else + shutdown_requested = 1; if (cpu_single_env) cpu_interrupt(cpu_single_env, CPU_INTERRUPT_EXIT); } @@ -8501,6 +8513,11 @@ void qemu_get_launch_info(int *argc, cha *opt_incoming = incoming; } +void qemu_powerdown_sighand(int signal) +{ + qemu_system_powerdown_request(); +} + int main(int argc, char **argv) { #ifdef CONFIG_GDBSTUB @@ -9475,6 +9492,8 @@ int main(int argc, char **argv) } } + signal(SIGINT, qemu_powerdown_sighand); + machine->init(ram_size, vga_ram_size, boot_devices, ds, kernel_filename, kernel_cmdline, initrd_filename, cpu_model); Index: b/qemu/sysemu.h =================================================================== --- a/qemu/sysemu.h +++ b/qemu/sysemu.h @@ -35,7 +35,7 @@ int qemu_reset_requested(void); int qemu_powerdown_requested(void); #if !defined(TARGET_SPARC) && !defined(TARGET_I386) // Please implement a power failure function to signal the OS -#define qemu_system_powerdown() do{}while(0) +#define qemu_system_powerdown() exit(0) #else void qemu_system_powerdown(void); #endif Index: b/qemu/sdl.c =================================================================== --- a/qemu/sdl.c +++ b/qemu/sdl.c @@ -469,7 +469,7 @@ static void sdl_refresh(DisplayState *ds break; case SDL_QUIT: if (!no_quit) { - qemu_system_shutdown_request(); + qemu_system_powerdown_request(); vm_start(); /* In case we're paused */ } break; |