From patchwork Tue May 4 07:17:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 51569 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A3908B7D27 for ; Tue, 4 May 2010 17:20:16 +1000 (EST) Received: from localhost ([127.0.0.1]:39898 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9CQO-0003lR-Sk for incoming@patchwork.ozlabs.org; Tue, 04 May 2010 03:20:12 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O9CPl-0003kz-HN for qemu-devel@nongnu.org; Tue, 04 May 2010 03:19:33 -0400 Received: from [140.186.70.92] (port=48115 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9CPb-0003fZ-4J for qemu-devel@nongnu.org; Tue, 04 May 2010 03:19:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9CPX-0001et-Tf for qemu-devel@nongnu.org; Tue, 04 May 2010 03:19:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18226) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9CPX-0001eI-Fu for qemu-devel@nongnu.org; Tue, 04 May 2010 03:19:19 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o447J6qp008987 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 4 May 2010 03:19:06 -0400 Received: from localhost (vpn-224-130.phx2.redhat.com [10.3.224.130]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o447J4OT002526; Tue, 4 May 2010 03:19:05 -0400 From: Amit Shah To: qemu list Date: Tue, 4 May 2010 12:47:18 +0530 Message-Id: <1272957442-7832-2-git-send-email-amit.shah@redhat.com> In-Reply-To: <1272957442-7832-1-git-send-email-amit.shah@redhat.com> References: <1272957442-7832-1-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Amit Shah , Paul Brook , Gerd Hoffmann , Juan Quintela Subject: [Qemu-devel] [PATCH v4 1/5] char: Let writers know how much data was written in case of errors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On writing errors, we just returned -1 even if some bytes were already written out. Ensure we return the number of bytes written before we return the error (on a subsequent call to qemu_chr_write()). Signed-off-by: Amit Shah --- qemu-char.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index ac65a1c..bc76000 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -522,8 +522,13 @@ static int unix_write(int fd, const uint8_t *buf, int len1) while (len > 0) { ret = write(fd, buf, len); if (ret < 0) { - if (errno != EINTR && errno != EAGAIN) - return -1; + if (errno != EINTR && errno != EAGAIN) { + if (len1 - len) { + return len1 - len; + } else { + return -1; + } + } } else if (ret == 0) { break; } else {