* [Qemu-devel] [PATCH] Monitor: Return before exiting with 'quit'
@ 2010-04-07 18:30 Luiz Capitulino
2010-04-20 8:29 ` Markus Armbruster
0 siblings, 1 reply; 2+ messages in thread
From: Luiz Capitulino @ 2010-04-07 18:30 UTC (permalink / raw)
To: qemu-devel; +Cc: armbru
The 'quit' Monitor command (implemented by do_quit()) calls
exit() directly, this is problematic under QMP because QEMU
exits before having a chance to send the ok response.
Clients don't know if QEMU exited because of a problem or
because the 'quit' command has been executed.
This commit fixes that by moving the exit() call to the main
loop, so that do_quit() requests the system to quit, instead
of calling exit() directly.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
monitor.c | 2 +-
sysemu.h | 2 ++
vl.c | 18 ++++++++++++++++++
3 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/monitor.c b/monitor.c
index 91d7da5..4c6275e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1017,7 +1017,7 @@ static void do_info_cpu_stats(Monitor *mon)
*/
static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
- exit(0);
+ qemu_system_exit_request();
return 0;
}
diff --git a/sysemu.h b/sysemu.h
index d0effa0..fa921df 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -45,9 +45,11 @@ void cpu_disable_ticks(void);
void qemu_system_reset_request(void);
void qemu_system_shutdown_request(void);
void qemu_system_powerdown_request(void);
+void qemu_system_exit_request(void);
int qemu_shutdown_requested(void);
int qemu_reset_requested(void);
int qemu_powerdown_requested(void);
+int qemu_exit_requested(void);
extern qemu_irq qemu_system_powerdown;
void qemu_system_reset(void);
diff --git a/vl.c b/vl.c
index e645006..44304b2 100644
--- a/vl.c
+++ b/vl.c
@@ -1780,6 +1780,7 @@ static int shutdown_requested;
static int powerdown_requested;
int debug_requested;
static int vmstop_requested;
+static int exit_requested;
int qemu_shutdown_requested(void)
{
@@ -1802,6 +1803,12 @@ int qemu_powerdown_requested(void)
return r;
}
+int qemu_exit_requested(void)
+{
+ /* just return it, we'll exit() anyway */
+ return exit_requested;
+}
+
static int qemu_debug_requested(void)
{
int r = debug_requested;
@@ -1872,6 +1879,12 @@ void qemu_system_powerdown_request(void)
qemu_notify_event();
}
+void qemu_system_exit_request(void)
+{
+ exit_requested = 1;
+ qemu_notify_event();
+}
+
#ifdef _WIN32
static void host_main_loop_wait(int *timeout)
{
@@ -2008,6 +2021,8 @@ static int vm_can_run(void)
return 0;
if (debug_requested)
return 0;
+ if (exit_requested)
+ return 0;
return 1;
}
@@ -2063,6 +2078,9 @@ static void main_loop(void)
if ((r = qemu_vmstop_requested())) {
vm_stop(r);
}
+ if (qemu_exit_requested()) {
+ exit(0);
+ }
}
pause_all_vcpus();
}
--
1.7.0.4.297.g6555b1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] Monitor: Return before exiting with 'quit'
2010-04-07 18:30 [Qemu-devel] [PATCH] Monitor: Return before exiting with 'quit' Luiz Capitulino
@ 2010-04-20 8:29 ` Markus Armbruster
0 siblings, 0 replies; 2+ messages in thread
From: Markus Armbruster @ 2010-04-20 8:29 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: qemu-devel
Luiz Capitulino <lcapitulino@redhat.com> writes:
> The 'quit' Monitor command (implemented by do_quit()) calls
> exit() directly, this is problematic under QMP because QEMU
> exits before having a chance to send the ok response.
>
> Clients don't know if QEMU exited because of a problem or
> because the 'quit' command has been executed.
Yes, that needs fixing.
> This commit fixes that by moving the exit() call to the main
> loop, so that do_quit() requests the system to quit, instead
> of calling exit() directly.
Matches how system_reset and system_powerdown work. Looks good to me.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-04-20 8:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-07 18:30 [Qemu-devel] [PATCH] Monitor: Return before exiting with 'quit' Luiz Capitulino
2010-04-20 8:29 ` Markus Armbruster
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).