From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O2KH4-0005Ka-Oe for qemu-devel@nongnu.org; Thu, 15 Apr 2010 04:18:10 -0400 Received: from [140.186.70.92] (port=34922 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O2KH3-0005K8-9M for qemu-devel@nongnu.org; Thu, 15 Apr 2010 04:18:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O2KH2-0001Ab-0B for qemu-devel@nongnu.org; Thu, 15 Apr 2010 04:18:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38956) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O2KH1-0001AQ-NP for qemu-devel@nongnu.org; Thu, 15 Apr 2010 04:18:07 -0400 From: Amit Shah Date: Thu, 15 Apr 2010 13:46:15 +0530 Message-Id: <1271319378-9811-2-git-send-email-amit.shah@redhat.com> In-Reply-To: <1271319378-9811-1-git-send-email-amit.shah@redhat.com> References: <1271319378-9811-1-git-send-email-amit.shah@redhat.com> Subject: [Qemu-devel] [PATCH v3 1/4] char: Let writers know how much data was written in case of errors List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu list Cc: Amit Shah , Gerd Hoffmann , paul@codesourcery.com 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 05df971..6aaa362 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 { -- 1.6.2.5