Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JMnse-0001hu-QS for qemu-devel@nongnu.org; Wed, 06 Feb 2008 12:16:16 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JMnsc-0001hh-HC for qemu-devel@nongnu.org; Wed, 06 Feb 2008 12:16:15 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JMnsc-0001he-9u for qemu-devel@nongnu.org; Wed, 06 Feb 2008 12:16:14 -0500 Received: from smtp02.citrix.com ([66.165.176.63]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JMnsc-0000b2-8Y for qemu-devel@nongnu.org; Wed, 06 Feb 2008 12:16:14 -0500 Received: from mariner.uk.xensource.com (mariner.uk.xensource.com [172.31.17.38]) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id m16HFV0a008310 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 6 Feb 2008 09:15:32 -0800 Received: from iwj by mariner.uk.xensource.com with local (Exim 4.63) (envelope-from ) id 1JMnqm-0002oh-QS for qemu-devel@nongnu.org; Wed, 06 Feb 2008 17:14:20 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <18345.60140.809776.605130@mariner.uk.xensource.com> Date: Wed, 6 Feb 2008 17:14:20 +0000 In-Reply-To: <18329.60886.909252.289862@mariner.uk.xensource.com> References: <18329.60886.909252.289862@mariner.uk.xensource.com> From: Ian Jackson Subject: [Qemu-devel] Re: [PATCH] check return value from read() and write() properly Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org iwj writes ("[PATCH] check return value from read() and write() properly"): > The system calls read and write may return less than the whole amount > requested for a number of reasons. So the idioms > if (read(fd, &object, sizeof(object)) != sizeof(object)) goto fail; > and even worse > if (read(fd, &object, sizeof(object)) < 0) goto fail; > are wrong. Additionally, read and write may sometimes return EINTR on > some systems so interruption is not desired or expected a loop is > needed. > > In the attached patch I introduce two new pairs of functions: I think this fix should be applied because it corrects bugs which might conceivably data loss. Thanks, Ian.