From patchwork Mon Sep 7 16:06:24 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 33107 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 5E0D9B7067 for ; Tue, 8 Sep 2009 02:53:14 +1000 (EST) Received: from localhost ([127.0.0.1]:40636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MkhSm-0006ll-JN for incoming@patchwork.ozlabs.org; Mon, 07 Sep 2009 12:53:08 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mkgk5-0007cS-1B for qemu-devel@nongnu.org; Mon, 07 Sep 2009 12:06:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mkgjz-0007Yn-7Q for qemu-devel@nongnu.org; Mon, 07 Sep 2009 12:06:56 -0400 Received: from [199.232.76.173] (port=34968 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mkgjx-0007YP-UW for qemu-devel@nongnu.org; Mon, 07 Sep 2009 12:06:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11330) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mkgjx-0003Xm-8z for qemu-devel@nongnu.org; Mon, 07 Sep 2009 12:06:49 -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 n87G6mPG011801 for ; Mon, 7 Sep 2009 12:06:48 -0400 Received: from zweiblum.home.kraxel.org (vpn2-9-74.ams2.redhat.com [10.36.9.74]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n87G6gBa029409; Mon, 7 Sep 2009 12:06:43 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id A7FE8700F5; Mon, 7 Sep 2009 18:06:26 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 7 Sep 2009 18:06:24 +0200 Message-Id: <1252339585-27797-23-git-send-email-kraxel@redhat.com> In-Reply-To: <1252339585-27797-1-git-send-email-kraxel@redhat.com> References: <1252339585-27797-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 22/23] monitor: fix muxing 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 make the mux driver send mux_in and mux_out events when switching focus while hooking up more handlers. stop using CharDriverState->focus in monitor.c, track state using the mux events instead. This also removes the implicit assumtion that a muxed monitor allways has mux channel 0. Signed-off-by: Gerd Hoffmann --- monitor.c | 33 ++++++++++++++++++++++----------- qemu-char.c | 3 +++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/monitor.c b/monitor.c index f5f4d0e..edf48f3 100644 --- a/monitor.c +++ b/monitor.c @@ -85,6 +85,8 @@ struct mon_fd_t { struct Monitor { CharDriverState *chr; + int mux_out; + int reset_seen; int flags; int suspend_cnt; uint8_t outbuf[1024]; @@ -129,7 +131,7 @@ static int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, void monitor_flush(Monitor *mon) { - if (mon && mon->outbuf_index != 0 && mon->chr->focus == 0) { + if (mon && mon->outbuf_index != 0 && !mon->mux_out) { qemu_chr_write(mon->chr, mon->outbuf, mon->outbuf_index); mon->outbuf_index = 0; } @@ -3111,23 +3113,34 @@ static void monitor_event(void *opaque, int event) switch (event) { case CHR_EVENT_MUX_IN: - readline_restart(mon->rs); - monitor_resume(mon); - monitor_flush(mon); + if (mon->reset_seen) { + readline_restart(mon->rs); + monitor_resume(mon); + monitor_flush(mon); + } else { + mon->suspend_cnt = 0; + } + mon->mux_out = 0; break; case CHR_EVENT_MUX_OUT: - if (mon->suspend_cnt == 0) - monitor_printf(mon, "\n"); - monitor_flush(mon); - monitor_suspend(mon); + if (mon->reset_seen) { + if (mon->suspend_cnt == 0) + monitor_printf(mon, "\n"); + monitor_flush(mon); + monitor_suspend(mon); + } else { + mon->suspend_cnt++; + } + mon->mux_out = 1; break; case CHR_EVENT_RESET: monitor_printf(mon, "QEMU %s monitor - type 'help' for more " "information\n", QEMU_VERSION); - if (mon->chr->focus == 0) + if (!mon->mux_out) readline_show_prompt(mon->rs); + mon->reset_seen = 1; break; } } @@ -3155,8 +3168,6 @@ void monitor_init(CharDriverState *chr, int flags) mon->chr = chr; mon->flags = flags; - if (mon->chr->focus != 0) - mon->suspend_cnt = 1; /* mux'ed monitors start suspended */ if (flags & MONITOR_USE_READLINE) { mon->rs = readline_init(mon, monitor_find_completion); monitor_read_command(mon, 0); diff --git a/qemu-char.c b/qemu-char.c index 2e71038..daa8587 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -456,8 +456,11 @@ static void mux_chr_update_read_handler(CharDriverState *chr) qemu_chr_add_handlers(d->drv, mux_chr_can_read, mux_chr_read, mux_chr_event, chr); } + if (-1 != chr->focus) + mux_chr_send_event(d, chr->focus, CHR_EVENT_MUX_OUT); chr->focus = d->mux_cnt; d->mux_cnt++; + mux_chr_send_event(d, chr->focus, CHR_EVENT_MUX_IN); } static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)