From patchwork Fri Nov 27 00:59:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 39606 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 3FC38B7B61 for ; Fri, 27 Nov 2009 12:26:35 +1100 (EST) Received: from localhost ([127.0.0.1]:49252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDpbU-0000Hu-9l for incoming@patchwork.ozlabs.org; Thu, 26 Nov 2009 20:26:32 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDpBq-0001y0-8p for qemu-devel@nongnu.org; Thu, 26 Nov 2009 20:00:02 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDpBk-0001rj-4w for qemu-devel@nongnu.org; Thu, 26 Nov 2009 20:00:01 -0500 Received: from [199.232.76.173] (port=48304 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDpBj-0001r7-Vl for qemu-devel@nongnu.org; Thu, 26 Nov 2009 19:59:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:10644) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDpBj-0004Tf-8P for qemu-devel@nongnu.org; Thu, 26 Nov 2009 19:59:55 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAR0xs2o023545 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 26 Nov 2009 19:59:54 -0500 Received: from localhost (vpn-10-232.rdu.redhat.com [10.11.10.232]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAR0xr5s004950; Thu, 26 Nov 2009 19:59:53 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 26 Nov 2009 22:59:05 -0200 Message-Id: <1259283550-3597-16-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1259283550-3597-1-git-send-email-lcapitulino@redhat.com> References: <1259283550-3597-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, avi@redhat.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 15/20] QMP: Disable monitor print functions 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 We still have handlers which will call monitor print functions in several places. Usually to report errors. If they do this when we are in control mode, we will be emitting garbage to our clients. To avoid this problem, this commit adds a way to disable those functions. If any of them is called when in control mode, we will emit a generic error. Although this is far from the perfect solution, it guarantees that only JSON is sent to Clients. Signed-off-by: Luiz Capitulino --- monitor.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/monitor.c b/monitor.c index 89115a6..a056503 100644 --- a/monitor.c +++ b/monitor.c @@ -98,6 +98,7 @@ struct mon_fd_t { typedef struct MonitorControl { QObject *id; + int print_enabled; JSONMessageParser parser; } MonitorControl; @@ -186,9 +187,13 @@ static void monitor_puts(Monitor *mon, const char *str) void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { - char buf[4096]; - vsnprintf(buf, sizeof(buf), fmt, ap); - monitor_puts(mon, buf); + if (mon->mc && !mon->mc->print_enabled) { + qemu_error_new(QERR_UNDEFINED_ERROR); + } else { + char buf[4096]; + vsnprintf(buf, sizeof(buf), fmt, ap); + monitor_puts(mon, buf); + } } void monitor_printf(Monitor *mon, const char *fmt, ...) @@ -272,7 +277,10 @@ static void monitor_json_emitter(Monitor *mon, const QObject *data) json = qobject_to_json(data); assert(json != NULL); + mon->mc->print_enabled = 1; monitor_printf(mon, "%s\n", qstring_get_str(json)); + mon->mc->print_enabled = 0; + QDECREF(json); }