diff -rbw -u qemu-snapshot-2005-07-25_23/cocoa.m qemu-snapshot-2005-07-25_23-on-quit/cocoa.m --- qemu-snapshot-2005-07-25_23/cocoa.m 2005-04-07 22:36:50.000000000 +0200 +++ qemu-snapshot-2005-07-25_23-on-quit/cocoa.m 2005-07-26 23:58:44.797315738 +0200 @@ -444,7 +444,7 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification { printf("Application will terminate\n"); - qemu_system_shutdown_request(); + qemu_system_shutdown_request(1); /* In order to avoid a crash */ exit(0); } diff -rbw -u qemu-snapshot-2005-07-25_23/hw/cuda.c qemu-snapshot-2005-07-25_23-on-quit/hw/cuda.c --- qemu-snapshot-2005-07-25_23/hw/cuda.c 2005-07-23 16:01:47.000000000 +0200 +++ qemu-snapshot-2005-07-25_23-on-quit/hw/cuda.c 2005-07-26 23:58:45.025293898 +0200 @@ -557,7 +557,7 @@ obuf[0] = CUDA_PACKET; obuf[1] = 0; cuda_send_packet_to_host(s, obuf, 2); - qemu_system_shutdown_request(); + qemu_system_shutdown_request(1); break; default: break; diff -rbw -u qemu-snapshot-2005-07-25_23/hw/pc.c qemu-snapshot-2005-07-25_23-on-quit/hw/pc.c --- qemu-snapshot-2005-07-25_23/hw/pc.c 2005-07-23 21:05:37.000000000 +0200 +++ qemu-snapshot-2005-07-25_23-on-quit/hw/pc.c 2005-07-26 23:58:45.120284798 +0200 @@ -323,7 +323,7 @@ shutdown_index++; if (shutdown_index == 8) { shutdown_index = 0; - qemu_system_shutdown_request(); + qemu_system_shutdown_request(-1); } } else { shutdown_index = 0; diff -rbw -u qemu-snapshot-2005-07-25_23/sdl.c qemu-snapshot-2005-07-25_23-on-quit/sdl.c --- qemu-snapshot-2005-07-25_23/sdl.c 2005-07-23 19:54:50.000000000 +0200 +++ qemu-snapshot-2005-07-25_23-on-quit/sdl.c 2005-07-26 23:58:45.214275794 +0200 @@ -413,7 +413,7 @@ sdl_process_key(&ev->key); break; case SDL_QUIT: - qemu_system_shutdown_request(); + qemu_system_shutdown_request(1); break; case SDL_MOUSEMOTION: if (gui_grab) { diff -rbw -u qemu-snapshot-2005-07-25_23/vl.c qemu-snapshot-2005-07-25_23-on-quit/vl.c --- qemu-snapshot-2005-07-25_23/vl.c 2005-07-24 20:44:55.000000000 +0200 +++ qemu-snapshot-2005-07-25_23-on-quit/vl.c 2005-07-26 23:59:56.408455447 +0200 @@ -144,6 +144,11 @@ #endif int graphic_depth = 15; int full_screen = 0; + +#define ON_QUIT_ASK_FILENAME "on_quit_ask" +int on_quit = 0; +const char * on_quit_filepath = NULL; + TextConsole *vga_console; CharDriverState *serial_hds[MAX_SERIAL_PORTS]; CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; @@ -2633,9 +2638,27 @@ cpu_interrupt(cpu_single_env, CPU_INTERRUPT_EXIT); } -void qemu_system_shutdown_request(void) +void qemu_system_shutdown_request(int s) { - shutdown_requested = 1; + + if (s == 1 && on_quit == 3) { // User power-off request and Popup message setting + int r,c; + + if( on_quit_filepath ) r = system(on_quit_filepath); + else { + char buf[1024]; + snprintf(buf, sizeof(buf), "%s/%s", CONFIG_QEMU_SHAREDIR, ON_QUIT_ASK_FILENAME); + r = system(buf); + } + c = WEXITSTATUS(r); + + if(c == 0) return; + if(c == 2) s = -1; // Simulate an APM power-off request + // else if r == -1, there was an error; if c == 1, then suspend; + // Either way, we suspend, for safety + } + + shutdown_requested = s; cpu_interrupt(cpu_single_env, CPU_INTERRUPT_EXIT); } @@ -2759,9 +2782,12 @@ if (vm_running) { ret = cpu_exec(env); if (shutdown_requested) { + if (on_quit == 0 || on_quit == 2 || on_quit == 3 || (on_quit == 1 && shutdown_requested == -1)) { ret = EXCP_INTERRUPT; break; } + shutdown_requested = 0; + } if (reset_requested) { reset_requested = 0; qemu_system_reset(); @@ -2864,6 +2890,9 @@ "-std-vga simulate a standard VGA card with VESA Bochs Extensions\n" " (default is CL-GD5446 PCI VGA)\n" #endif + "-on-quit [ignore|suspend|ask|