From patchwork Wed Apr 7 18:30:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 49640 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 327C0B7D29 for ; Thu, 8 Apr 2010 04:57:59 +1000 (EST) Received: from localhost ([127.0.0.1]:53432 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NzaRn-0002Lu-W8 for incoming@patchwork.ozlabs.org; Wed, 07 Apr 2010 14:57:56 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nza1I-00027l-HE for qemu-devel@nongnu.org; Wed, 07 Apr 2010 14:30:32 -0400 Received: from [140.186.70.92] (port=38990 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nza1G-00026L-6O for qemu-devel@nongnu.org; Wed, 07 Apr 2010 14:30:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Nza1A-0004Lx-2K for qemu-devel@nongnu.org; Wed, 07 Apr 2010 14:30:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34481) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Nza18-0004LY-I5 for qemu-devel@nongnu.org; Wed, 07 Apr 2010 14:30:23 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o37IUKIm021929 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 7 Apr 2010 14:30:20 -0400 Received: from localhost (vpn-8-238.rdu.redhat.com [10.11.8.238]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o37IUG1k022982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 7 Apr 2010 14:30:19 -0400 Date: Wed, 7 Apr 2010 15:30:15 -0300 From: Luiz Capitulino To: qemu-devel@nongnu.org Message-ID: <20100407153015.02aaf5d8@redhat.com> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: armbru@redhat.com Subject: [Qemu-devel] [PATCH] Monitor: Return before exiting with 'quit' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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(); }