From patchwork Sun Sep 7 12:24:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zifei Tong X-Patchwork-Id: 386701 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41570140077 for ; Sun, 7 Sep 2014 23:40:26 +1000 (EST) Received: from localhost ([::1]:38276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XQchZ-000450-Ph for incoming@patchwork.ozlabs.org; Sun, 07 Sep 2014 09:40:21 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=JGAQuBDuMVlHJ9dpz5qy5dQps0G3ymi8RkMmty4Yj2Y=; b=mB8qgpFpP8x9+yH5inhX/PzBGnbPm8oTqRhGUKj3efNuAUy0BSQWV3Gx0ekqGv+Rwy LzLXlO4ntkart+Jl5apTYzQ2qlM6jtF2S53hbCMnM2L91GP72yZh6h0rEa1h5NeeVPEJ ZUWP2lOZCba5frvcsLYufs7ofOclsEJsHkypBYPiinhiM/xmdP6zofgmQZLmTaDEuw60 6vuoC85/Txzxyhk0qr0Cl2K8ebcwrf5upeZVKOo17k8wbGr6fD+dd6/nS3HHqP0QqgOq ZNEPCGpswPHwoqDRdegOGuQQONiEyKyM/R7SAMra1zXSLa/gfhnxiJuYgua1jtaS/EaK 6yJA== X-Received: by 10.68.173.98 with SMTP id bj2mr3470897pbc.157.1410092717000; Sun, 07 Sep 2014 05:25:17 -0700 (PDT) Received: from zifeitong-cad (li388-184.members.linode.com. [106.187.45.184]) by mx.google.com with ESMTPSA id y4sm6453655pdm.1.2014.09.07.05.25.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Sep 2014 05:25:16 -0700 (PDT) Received: by zifeitong-cad (sSMTP sendmail emulation); Sun, 07 Sep 2014 20:25:07 +0800 From: Zifei Tong To: qemu-devel@nongnu.org Date: Sun, 7 Sep 2014 20:24:26 +0800 Message-Id: <1410092666-17405-1-git-send-email-zifeitong@gmail.com> X-Mailer: git-send-email 2.1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c02::229 X-Mailman-Approved-At: Sun, 07 Sep 2014 09:39:42 -0400 Cc: Kirill Batuzov , Anthony Liguori , Nikolay Nikolaev , Zifei Tong Subject: [Qemu-devel] [PATCH] qemu-char: Do not disconnect when there's data for reading 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 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;