From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XQbX1-0000xn-Kp for qemu-devel@nongnu.org; Sun, 07 Sep 2014 08:25:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XQbWw-0004jp-Sc for qemu-devel@nongnu.org; Sun, 07 Sep 2014 08:25:23 -0400 Received: from mail-pd0-x229.google.com ([2607:f8b0:400e:c02::229]:64171) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XQbWw-0004ji-LJ for qemu-devel@nongnu.org; Sun, 07 Sep 2014 08:25:18 -0400 Received: by mail-pd0-f169.google.com with SMTP id y10so9603679pdj.0 for ; Sun, 07 Sep 2014 05:25:17 -0700 (PDT) From: Zifei Tong Date: Sun, 7 Sep 2014 20:24:26 +0800 Message-Id: <1410092666-17405-1-git-send-email-zifeitong@gmail.com> Subject: [Qemu-devel] [PATCH] qemu-char: Do not disconnect when there's data for reading List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kirill Batuzov , Anthony Liguori , Nikolay Nikolaev , Zifei Tong After commit 812c1057f6175ac9a9829fa2920a2b5783814193 (Handle G_IO_HUP in tcp_chr_read for tcp chardev), the connection is disconnected when in G_IO_HUP condition. However, it's possible that the channel is in G_IO_IN condition at the same time, meaning there is data for reading. In that case, the remaining data is not handled. I saw a related bug when running socat in write-only mode, with $ echo "quit" | socat -u - UNIX-CONNECT:qemu-monitor the monitor won't not run the 'quit' command. CC: Kirill Batuzov CC: Nikolay Nikolaev CC: Anthony Liguori Signed-off-by: Zifei Tong --- qemu-char.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu-char.c b/qemu-char.c index 1a8d9aa..5018c3a 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2706,7 +2706,7 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) uint8_t buf[READ_BUF_LEN]; int len, size; - if (cond & G_IO_HUP) { + if (!(cond & G_IO_IN) && (cond & G_IO_HUP)) { /* connection closed */ tcp_chr_disconnect(chr); return TRUE; -- 2.1.0