From patchwork Thu Mar 4 15:56:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 46935 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 03659B7D82 for ; Fri, 5 Mar 2010 03:35:29 +1100 (EST) Received: from localhost ([127.0.0.1]:47769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnE1F-0005kM-Hj for incoming@patchwork.ozlabs.org; Thu, 04 Mar 2010 11:35:25 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NnDQr-0000jW-5j for qemu-devel@nongnu.org; Thu, 04 Mar 2010 10:57:49 -0500 Received: from [199.232.76.173] (port=35969 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnDQo-0000fs-14 for qemu-devel@nongnu.org; Thu, 04 Mar 2010 10:57:46 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NnDQT-0000Jd-Bg for qemu-devel@nongnu.org; Thu, 04 Mar 2010 10:57:45 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:39625) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NnDQR-0000HG-8z for qemu-devel@nongnu.org; Thu, 04 Mar 2010 10:57:24 -0500 Received: from blackfin.pond.sub.org (pD9E38041.dip.t-dialin.net [217.227.128.65]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 2A396276DAD for ; Thu, 4 Mar 2010 16:57:13 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 09FD4F2; Thu, 4 Mar 2010 16:57:11 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 4 Mar 2010 16:56:27 +0100 Message-Id: <1267718231-13303-7-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1267718231-13303-1-git-send-email-armbru@redhat.com> References: <1267718231-13303-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Luiz Capitulino Subject: [Qemu-devel] [PATCH 06/50] monitor: Separate "default monitor" and "current monitor" cleanly 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 Commits 376253ec..731b0364 introduced global variable cur_mon, which points to the "default monitor" (if any), except during execution of monitor_read() or monitor_control_read() it points to the monitor from which we're reading instead (the "current monitor"). Monitor command handlers run within monitor_read() or monitor_control_read(). Default monitor and current monitor are really separate things, and squashing them together is confusing and error-prone. For instance, usb_host_scan() can run both in "info usbhost" and periodically via usb_host_auto_check(). It prints to cur_mon, which is what we want in the former case: the monitor executing "info usbhost". But since that's the default monitor in the latter case, it periodically spams the default monitor there. A few places use cur_mon to log stuff to the default monitor. If we ever log something while cur_mon points to current monitor instead of default monitor, the log temporarily "jumps" to another monitor. Whether that can or cannot happen isn't always obvious. Maybe logging to the default monitor (which may not even exist) is a bad idea, and we should log to stderr or a logfile instead. But that's outside the scope of this commit. Change cur_mon to point to the current monitor. Create new default_mon to point to the default monitor. Update users of cur_mon accordingly. This fixes the periodical spamming of the default monitor by usb_host_scan(). It also stops "log jumping", should that problem exist. Signed-off-by: Markus Armbruster --- audio/audio.c | 4 ++-- monitor.c | 7 ++++--- monitor.h | 1 + slirp/misc.c | 2 +- vnc.c | 5 ++--- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index 2a20e5b..dbf0b96 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -330,10 +330,10 @@ void AUD_vlog (const char *cap, const char *fmt, va_list ap) { if (conf.log_to_monitor) { if (cap) { - monitor_printf(cur_mon, "%s: ", cap); + monitor_printf(default_mon, "%s: ", cap); } - monitor_vprintf(cur_mon, fmt, ap); + monitor_vprintf(default_mon, fmt, ap); } else { if (cap) { diff --git a/monitor.c b/monitor.c index b16c8c3..8e2e5c3 100644 --- a/monitor.c +++ b/monitor.c @@ -177,7 +177,8 @@ static QLIST_HEAD(mon_list, Monitor) mon_list; static const mon_cmd_t mon_cmds[]; static const mon_cmd_t info_cmds[]; -Monitor *cur_mon = NULL; +Monitor *cur_mon; +Monitor *default_mon; static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque); @@ -4621,8 +4622,8 @@ void monitor_init(CharDriverState *chr, int flags) } QLIST_INSERT_HEAD(&mon_list, mon, entry); - if (!cur_mon || (flags & MONITOR_IS_DEFAULT)) - cur_mon = mon; + if (!default_mon || (flags & MONITOR_IS_DEFAULT)) + default_mon = mon; } static void bdrv_password_cb(Monitor *mon, const char *password, void *opaque) diff --git a/monitor.h b/monitor.h index fc09505..c481c9d 100644 --- a/monitor.h +++ b/monitor.h @@ -7,6 +7,7 @@ #include "block.h" extern Monitor *cur_mon; +extern Monitor *default_mon; /* flags for monitor_init */ #define MONITOR_IS_DEFAULT 0x01 diff --git a/slirp/misc.c b/slirp/misc.c index dcb1dc1..1aeb401 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -260,7 +260,7 @@ void lprint(const char *format, ...) va_list args; va_start(args, format); - monitor_vprintf(cur_mon, format, args); + monitor_vprintf(default_mon, format, args); va_end(args); } diff --git a/vnc.c b/vnc.c index db34b0e..712043f 100644 --- a/vnc.c +++ b/vnc.c @@ -1046,11 +1046,10 @@ static void audio_capture(void *opaque, void *buf, int size) static void audio_add(VncState *vs) { - Monitor *mon = cur_mon; struct audio_capture_ops ops; if (vs->audio_cap) { - monitor_printf(mon, "audio already running\n"); + monitor_printf(default_mon, "audio already running\n"); return; } @@ -1060,7 +1059,7 @@ static void audio_add(VncState *vs) vs->audio_cap = AUD_add_capture(&vs->as, &ops, vs); if (!vs->audio_cap) { - monitor_printf(mon, "Failed to add audio capture\n"); + monitor_printf(default_mon, "Failed to add audio capture\n"); } }