From patchwork Thu May 23 08:47:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 245859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 825F32C016A for ; Thu, 23 May 2013 19:20:50 +1000 (EST) Received: from localhost ([::1]:34055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfRGP-0004e8-Ed for incoming@patchwork.ozlabs.org; Thu, 23 May 2013 04:52:45 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfRDt-00010F-U6 for qemu-devel@nongnu.org; Thu, 23 May 2013 04:50:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UfRDs-0002oj-Fv for qemu-devel@nongnu.org; Thu, 23 May 2013 04:50:09 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:58397) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfRDr-0002nJ-PI for qemu-devel@nongnu.org; Thu, 23 May 2013 04:50:08 -0400 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 23 May 2013 18:36:58 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 23 May 2013 18:36:55 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 0321A2CE804A for ; Thu, 23 May 2013 18:50:00 +1000 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r4N8ZfsU20971624 for ; Thu, 23 May 2013 18:35:41 +1000 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r4N8nxWT011200 for ; Thu, 23 May 2013 18:49:59 +1000 Received: from RH63Wenchao.localdomain ([9.77.176.251]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r4N8lOe0006827; Thu, 23 May 2013 18:49:54 +1000 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Thu, 23 May 2013 16:47:15 +0800 Message-Id: <1369298836-17416-5-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1369298836-17416-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1369298836-17416-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13052308-9264-0000-0000-000003CDB105 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.146 Cc: kwolf@redhat.com, phrdina@redhat.com, stefanha@gmail.com, armbru@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V2 4/5] util: add new function message_printf() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This function takes an input parameter *output, which can be specified by caller as stderr, stdout or a monitor. error_vprintf() now calls message_vprintf(), which is a static function added in this patch. Signed-off-by: Wenchao Xia Reviewed-by: Eric Blake Reviewed-by: Luiz Capitulino --- include/qemu/error-report.h | 13 +++++++++++++ util/qemu-error.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index c902cc1..cdde78b 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -14,6 +14,8 @@ #define QEMU_ERROR_H #include +#include +#include "qemu/typedefs.h" typedef struct Location { /* all members are private to qemu-error.c */ @@ -32,6 +34,17 @@ void loc_set_none(void); void loc_set_cmdline(char **argv, int idx, int cnt); void loc_set_file(const char *fname, int lno); +typedef struct QemuOutput { + enum { OUTPUT_STREAM, OUTPUT_MONITOR } kind; + union { + FILE *stream; + Monitor *monitor; + }; +} QemuOutput; + +void message_printf(const QemuOutput *output, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); + void error_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); diff --git a/util/qemu-error.c b/util/qemu-error.c index 08a36f4..c7ff0a8 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -13,6 +13,25 @@ #include #include "monitor/monitor.h" +static GCC_FMT_ATTR(2, 0) +void message_vprintf(const QemuOutput *output, const char *fmt, va_list ap) +{ + if (output->kind == OUTPUT_STREAM) { + vfprintf(output->stream, fmt, ap); + } else if (output->kind == OUTPUT_MONITOR) { + monitor_vprintf(output->monitor, fmt, ap); + } +} + +void message_printf(const QemuOutput *output, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + message_vprintf(output, fmt, ap); + va_end(ap); +} + /* * Print to current monitor if we have one, else to stderr. * TODO should return int, so callers can calculate width, but that @@ -20,11 +39,16 @@ */ void error_vprintf(const char *fmt, va_list ap) { + QemuOutput output; + if (cur_mon) { - monitor_vprintf(cur_mon, fmt, ap); + output.kind = OUTPUT_MONITOR; + output.monitor = cur_mon; } else { - vfprintf(stderr, fmt, ap); + output.kind = OUTPUT_STREAM; + output.stream = stderr; } + message_vprintf(&output, fmt, ap); } /*