From patchwork Mon Feb 8 17:02:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8252311 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D3BEC9F1C1 for ; Mon, 8 Feb 2016 17:03:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3020A203B8 for ; Mon, 8 Feb 2016 17:03:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3D269203B7 for ; Mon, 8 Feb 2016 17:03:44 +0000 (UTC) Received: from localhost ([::1]:46834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpDz-00033h-Ir for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Feb 2016 12:03:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43190) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpDj-0002yv-2f for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSpDh-0006eJ-Vy for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:27 -0500 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:37275) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpDh-0006eD-PX for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:25 -0500 Received: by mail-wm0-x22f.google.com with SMTP id g62so125499072wme.0 for ; Mon, 08 Feb 2016 09:03:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Sx4x0osYMKf9Rk6ZJB0H9OGPOsGX11E6yveZhdgc5xQ=; b=a1wrFl/Hu2f8QEUuo/+dSg1n9K4948PrLdsyt6hq2Kg0dSEKwUPnG+FjPdLLrkHdd8 znDq/sONmEvJ6dwVdH9XD4GKduj2OrazZJsKvLxcI9NK5Ptys1rcGQOBYZXvGmaUNiKa UcaIvK4QIZrjuFvYXAUZp9gw7FVX5OHmfVqfR8vTt3FbNhFGC9+hU6hU5q/F9w+sBnBt KzJ0IpuSzJc0CFzTvmNcIRwSN0VprkDPh8idYdsydPJ96EQfXtCu0EqgQrafo2ihfhmo O8yYkoRmkAU4YfbrB5i0HnuOAiHheL/heKer2SR9DqOfrdi4dDnyUWGQ1p8eNia7A6Vr UXGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Sx4x0osYMKf9Rk6ZJB0H9OGPOsGX11E6yveZhdgc5xQ=; b=deVxRvEhnlVx+Xrx2/tH0eTlpSteeqr0GnUBRWecNN3vh99oUx9mdIscP2S0HNW0nW oowyRBiQ0usqswlgxFjA3wZtijD+i4u5lVzlJOVRINsj/iZHKeaT051VWCXQbQ3sqVS1 oWt6QOUtjrwBFisafrBkb3or8mwk44QVSTs94DQVMxDssN5neXbneTqofP/HMeeEkCgw IvkWAzX6VQm23kfI1TxRCZXTewXAb3KoNQkHk5zKXdUZPCVCWZN5wdcrKVCN2fW+hYmO ho1w/84CP0TG10XKm8wM1wtjZ/ihsowGmo4+W7vfDRjP+BeYJyXmb7fJJeeR0X1pzTTG Cd6Q== X-Gm-Message-State: AG10YOSIlJlpAML2+cpIZln0azV0BG6+8ISlYdz5Dt5a7gPoR4uQU6oLIzvU+j+LOAeURQ== X-Received: by 10.194.156.199 with SMTP id wg7mr33843664wjb.114.1454951005059; Mon, 08 Feb 2016 09:03:25 -0800 (PST) Received: from 640k.lan (94-39-141-130.adsl-ull.clienti.tiscali.it. [94.39.141.130]) by smtp.gmail.com with ESMTPSA id b1sm30651442wjy.0.2016.02.08.09.03.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Feb 2016 09:03:24 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 8 Feb 2016 18:02:54 +0100 Message-Id: <1454950999-64128-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1454950999-64128-1-git-send-email-pbonzini@redhat.com> References: <1454950999-64128-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22f Cc: Ashley Jonathan Subject: [Qemu-devel] [PULL 03/28] qemu-char: Keep pty slave file descriptor open until the master is closed 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If a process opens the slave pts device, writes data to it, then immediately closes it, the data doesn't reliably get delivered to the emulated serial port. This seems to be because a read of the master pty device returns EIO on Linux if no process has the pts device open, even when data is waiting "in the pipe". A fix seems to be for QEMU to keep the pts file descriptor open until the pty is closed, as per the below patch. Signed-off-by: Ashley Jonathan Message-Id: Reviewed-by: Michael Tokarev Signed-off-by: Paolo Bonzini --- qemu-char.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qemu-char.c b/qemu-char.c index 927c47e..1fbccf0 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -1171,6 +1171,7 @@ typedef struct { int connected; guint timer_tag; guint open_tag; + int slave_fd; } PtyCharDriver; static void pty_chr_update_read_handler_locked(CharDriverState *chr); @@ -1347,6 +1348,7 @@ static void pty_chr_close(struct CharDriverState *chr) qemu_mutex_lock(&chr->chr_write_lock); pty_chr_state(chr, 0); + close(s->slave_fd); object_unref(OBJECT(s->ioc)); if (s->timer_tag) { g_source_remove(s->timer_tag); @@ -1374,7 +1376,6 @@ static CharDriverState *qemu_chr_open_pty(const char *id, return NULL; } - close(slave_fd); qemu_set_nonblock(master_fd); chr = qemu_chr_alloc(common, errp); @@ -1399,6 +1400,7 @@ static CharDriverState *qemu_chr_open_pty(const char *id, chr->explicit_be_open = true; s->ioc = QIO_CHANNEL(qio_channel_file_new_fd(master_fd)); + s->slave_fd = slave_fd; s->timer_tag = 0; return chr;