From patchwork Fri Apr 19 15:32:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 238039 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 0B3052C01FD for ; Sat, 20 Apr 2013 01:32:53 +1000 (EST) Received: from localhost ([::1]:56308 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTDIx-0005Ms-1z for incoming@patchwork.ozlabs.org; Fri, 19 Apr 2013 11:32:51 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTDIX-0005Hl-Kq for qemu-devel@nongnu.org; Fri, 19 Apr 2013 11:32:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UTDIR-0002XT-Mr for qemu-devel@nongnu.org; Fri, 19 Apr 2013 11:32:25 -0400 Received: from mail-ee0-f41.google.com ([74.125.83.41]:42882) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTDIR-0002XG-Hf for qemu-devel@nongnu.org; Fri, 19 Apr 2013 11:32:19 -0400 Received: by mail-ee0-f41.google.com with SMTP id c1so1904416eek.28 for ; Fri, 19 Apr 2013 08:32:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=XPobBaznBp2ezYI7ooZwvFy0eC7EpwMMp67ahuZhbX8=; b=TJ1VyuqfzBvlF7a57/TnA/4AANw3SUaqp1LtDRzQ2k9EEBexwXzSjkqNk9w/9Dyre2 Kn6JwQ2Ct8wpJXbaRcb5D8ix4RNNGHzr+A5Zg1qG91SOs1JsvHA7WV1cYHgoztNPB2Fm TJNFXyUMapFYDOp2+CufspiBJpsAO2NohJmRwzsiI/vf5dBeGSyLDyuJ21vMtwwV+ACx APE4tgo4Pc6XA0eQlIkJYnLOB9lDOCAfg1l0M7xXjVzfkrvyzJCIsDDTzDgp6XGGdJrN fFAq9rXrHAgPL3SO7TbiXTLW1qQ2DHLZDFkl22bITKpnToQrSiosQlElaZ+0ui0J+Jvb aTVg== X-Received: by 10.14.173.71 with SMTP id u47mr7504585eel.24.1366385538813; Fri, 19 Apr 2013 08:32:18 -0700 (PDT) Received: from localhost.localdomain (93-34-176-20.ip50.fastwebnet.it. [93.34.176.20]) by mx.google.com with ESMTPS id cb50sm23792906eeb.14.2013.04.19.08.32.17 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 19 Apr 2013 08:32:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 19 Apr 2013 17:32:08 +0200 Message-Id: <1366385529-10329-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1366385529-10329-1-git-send-email-pbonzini@redhat.com> References: <1366385529-10329-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 74.125.83.41 Cc: amit.shah@redhat.com, aliguori@us.ibm.com, kraxel@redhat.com Subject: [Qemu-devel] [PATCH v2 3/4] qemu-char: correct return value from chr_read functions 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 Even if a CharDriverState's source is blocked by the front-end, it must not be dropped. The IOWatchPoll that wraps it will take care of adding and removing it to the main loop. Only remove the source when the channel is closed; and in that case, make sure that the wrapping IOWatchPoll is removed too. These should just be theoretical bugs. Signed-off-by: Paolo Bonzini --- qemu-char.c | 22 ++++++++++++++++------ 1 files changed, 16 insertions(+), 6 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index d14888d..6e897da 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -781,12 +781,16 @@ static gboolean fd_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) len = s->max_size; } if (len == 0) { - return FALSE; + return TRUE; } status = g_io_channel_read_chars(chan, (gchar *)buf, len, &bytes_read, NULL); if (status == G_IO_STATUS_EOF) { + if (s->fd_in_tag) { + g_source_remove(s->fd_in_tag); + s->fd_in_tag = 0; + } qemu_chr_be_event(chr, CHR_EVENT_CLOSED); return FALSE; } @@ -1105,8 +1109,9 @@ static gboolean pty_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) len = sizeof(buf); if (len > s->read_bytes) len = s->read_bytes; - if (len == 0) - return FALSE; + if (len == 0) { + return TRUE; + } status = g_io_channel_read_chars(s->fd, (gchar *)buf, len, &size, NULL); if (status != G_IO_STATUS_NORMAL) { pty_chr_state(chr, 0); @@ -2238,13 +2243,18 @@ static gboolean udp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) gsize bytes_read = 0; GIOStatus status; - if (s->max_size == 0) - return FALSE; + if (s->max_size == 0) { + return TRUE; + } status = g_io_channel_read_chars(s->chan, (gchar *)s->buf, sizeof(s->buf), &bytes_read, NULL); s->bufcnt = bytes_read; s->bufptr = s->bufcnt; if (status != G_IO_STATUS_NORMAL) { + if (s->tag) { + g_source_remove(s->tag); + s->tag = 0; + } return FALSE; } @@ -2497,7 +2507,7 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) int len, size; if (!s->connected || s->max_size <= 0) { - return FALSE; + return TRUE; } len = sizeof(buf); if (len > s->max_size)