From patchwork Thu Aug 13 14:31:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 31333 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4D1D9B6F20 for ; Fri, 14 Aug 2009 01:14:01 +1000 (EST) Received: from localhost ([127.0.0.1]:59063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mbc05-0006HK-8O for incoming@patchwork.ozlabs.org; Thu, 13 Aug 2009 11:13:57 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MbbNF-00039J-Ur for qemu-devel@nongnu.org; Thu, 13 Aug 2009 10:33:50 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MbbNB-00031x-RP for qemu-devel@nongnu.org; Thu, 13 Aug 2009 10:33:49 -0400 Received: from [199.232.76.173] (port=55098 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MbbNB-00031l-JY for qemu-devel@nongnu.org; Thu, 13 Aug 2009 10:33:45 -0400 Received: from mx2.redhat.com ([66.187.237.31]:48848) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MbbNA-0003P7-Re for qemu-devel@nongnu.org; Thu, 13 Aug 2009 10:33:45 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7DEVhhc004349; Thu, 13 Aug 2009 10:31:43 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n7DEVgul015551; Thu, 13 Aug 2009 10:31:42 -0400 Received: from zweiblum.home.kraxel.org (vpn2-8-91.ams2.redhat.com [10.36.8.91]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n7DEVda4020830; Thu, 13 Aug 2009 10:31:40 -0400 Message-ID: <4A8423CA.2050108@redhat.com> Date: Thu, 13 Aug 2009 16:31:38 +0200 From: Gerd Hoffmann User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Lightning/1.0pre Thunderbird/3.0b2 MIME-Version: 1.0 To: Markus Armbruster Subject: Re: [Qemu-devel] [PATCH] qdev: add return value to init() callbacks. References: <1250092766-23986-1-git-send-email-kraxel@redhat.com> <200908122028.41012.paul@codesourcery.com> <4A831C47.3070309@redhat.com> <873a7w2q6n.fsf@pike.pond.sub.org> <4A83C562.1090802@redhat.com> <87tz0cytem.fsf@pike.pond.sub.org> <4A83F389.7080302@redhat.com> <87r5vgx7n9.fsf@pike.pond.sub.org> In-Reply-To: <87r5vgx7n9.fsf@pike.pond.sub.org> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Paul Brook , qemu-devel@nongnu.org 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 > save output object > set up output object to point to the appropriate sink > call stuff (may print messages via output object to sink) > restore output object i.e. something like the attached patch? (qemu-kvm might need some more care due to the io thread). cheers, Gerd diff --git a/monitor.c b/monitor.c index 362322b..7163d21 100644 --- a/monitor.c +++ b/monitor.c @@ -2839,6 +2839,7 @@ static void monitor_handle_command(Monitor *mon, const char *cmdline) goto fail; } + qemu_errors_to_mon(mon); switch(nb_args) { case 0: handler_0 = cmd->handler; @@ -2890,8 +2891,10 @@ static void monitor_handle_command(Monitor *mon, const char *cmdline) break; default: monitor_printf(mon, "unsupported number of arguments: %d\n", nb_args); - goto fail; + break; } + qemu_errors_to_previous(); + fail: for(i = 0; i < MAX_ARGS; i++) qemu_free(str_allocated[i]); @@ -3256,3 +3259,69 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, if (err && completion_cb) completion_cb(opaque, err); } + +typedef struct QemuErrorSink QemuErrorSink; +struct QemuErrorSink { + enum { + ERR_SINK_FILE, + ERR_SINK_MONITOR, + } dest; + union { + FILE *fp; + Monitor *mon; + }; + QemuErrorSink *previous; +}; + +static QemuErrorSink *qemu_error_sink; + +void qemu_errors_to_file(FILE *fp) +{ + QemuErrorSink *sink; + + sink = qemu_mallocz(sizeof(*sink)); + sink->dest = ERR_SINK_FILE; + sink->fp = fp; + sink->previous = qemu_error_sink; + qemu_error_sink = sink; +} + +void qemu_errors_to_mon(Monitor *mon) +{ + QemuErrorSink *sink; + + sink = qemu_mallocz(sizeof(*sink)); + sink->dest = ERR_SINK_MONITOR; + sink->mon = mon; + sink->previous = qemu_error_sink; + qemu_error_sink = sink; +} + +void qemu_errors_to_previous(void) +{ + QemuErrorSink *sink; + + assert(qemu_error_sink != NULL); + sink = qemu_error_sink; + qemu_error_sink = sink->previous; + qemu_free(sink); +} + +void qemu_error(char *fmt, ...) +{ + va_list args; + + assert(qemu_error_sink != NULL); + switch (qemu_error_sink->dest) { + case ERR_SINK_FILE: + va_start(args, fmt); + vfprintf(qemu_error_sink->fp, fmt, args); + va_end(args); + break; + case ERR_SINK_MONITOR: + va_start(args, fmt); + monitor_vprintf(qemu_error_sink->mon, fmt, args); + va_end(args); + break; + } +} diff --git a/sysemu.h b/sysemu.h index dffb2f1..1875bf7 100644 --- a/sysemu.h +++ b/sysemu.h @@ -65,6 +65,11 @@ int qemu_savevm_state_complete(QEMUFile *f); int qemu_savevm_state(QEMUFile *f); int qemu_loadvm_state(QEMUFile *f); +void qemu_errors_to_file(FILE *fp); +void qemu_errors_to_mon(Monitor *mon); +void qemu_errors_to_previous(void); +void qemu_error(char *fmt, ...) __attribute__ ((format(printf, 1, 2))); + #ifdef _WIN32 /* Polling handling */ diff --git a/vl.c b/vl.c index 8b2b289..c1b11cd 100644 --- a/vl.c +++ b/vl.c @@ -4815,6 +4815,7 @@ int main(int argc, char **argv, char **envp) CPUState *env; int show_vnc_port = 0; + qemu_errors_to_file(stderr); qemu_cache_utils_init(envp); LIST_INIT (&vm_change_state_head);