From f358a5c2b39fb51b86e2cb8a15aeaa51e8d85974 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: <405603258af5154387bea676be1f904b6713f6ae.1368111913.git.minovotn@redhat.com> References: <405603258af5154387bea676be1f904b6713f6ae.1368111913.git.minovotn@redhat.com> From: Amit Shah Date: Wed, 24 Apr 2013 08:18:36 +0200 Subject: [PATCH 62/65] qemu-char: correct return value from chr_read functions RH-Author: Amit Shah Message-id: Patchwork-id: 50840 O-Subject: [RHEL6.5 qemu-kvm PATCH 62/65] qemu-char: correct return value from chr_read functions Bugzilla: 909059 RH-Acked-by: Hans de Goede RH-Acked-by: Gerd Hoffmann RH-Acked-by: Paolo Bonzini From: Paolo Bonzini 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 Message-id: 1366385529-10329-4-git-send-email-pbonzini@redhat.com Signed-off-by: Anthony Liguori (cherry picked from commit cdbf6e165988ab9d7c01da03b9e27bb8ac0c76aa) Signed-off-by: Amit Shah --- qemu-char.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) Signed-off-by: Michal Novotny --- qemu-char.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index feab352..4db0a22 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -724,12 +724,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; } @@ -1050,8 +1054,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); @@ -2007,13 +2012,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; } @@ -2259,7 +2269,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) -- 1.7.11.7