mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 17:23:56 -06:00
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
This commit is contained in:
parent
6f382b5ec0
commit
5b08fc106d
3 changed files with 28 additions and 10 deletions
27
vl.c
27
vl.c
|
@ -7621,6 +7621,8 @@ static int main_loop(void)
|
|||
timeout = 0;
|
||||
}
|
||||
} else {
|
||||
if (shutdown_requested)
|
||||
break;
|
||||
timeout = 10;
|
||||
}
|
||||
#ifdef CONFIG_PROFILER
|
||||
|
@ -8185,6 +8187,26 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
|
|||
|
||||
#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 @@ int main(int argc, char **argv)
|
|||
#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++) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue