From patchwork Sat Aug 11 21:24:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 10692 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 91F6923E53 for ; Sat, 11 Aug 2012 21:24:41 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 4514BA18DD9 for ; Sat, 11 Aug 2012 21:24:41 +0000 (UTC) Received: by ghbg10 with SMTP id g10so2321153ghb.11 for ; Sat, 11 Aug 2012 14:24:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=/9eZ2z49kqU/lvmRIhXCpmFepM+PDCnwPTgJiYDAaS0=; b=Eu+0xGw4PbR065Ds7CXCcc5Odx5aFYFVYsJK8SAAo5Uc7n+A98872YjrDStdVZYzgB XxROPH08bH2xrodNVlebuvhChNKj6OScog4Q3vjQDsbJvJk3FPybbkQY9WUqLR9bauoM z7aJeRY86fEplzRdpgb0LPO/v/7xdHK2Rk5YkrLvPl8UZg2kfIuQdaeupgZAI6lRgJpn GFd7i8O/LLJbayGF+n+1qmB9W0Y/ewXsk8zIB1XrWyJxHh3VhJE5asJCPLwdsWAEgHvu BmvzcgtM/5WRfcNoC35+Td9Jd7dHThxfFVPscDadq5W/0eeczWb5spaqwoXPff5Nn221 Jc9A== Received: by 10.43.86.7 with SMTP id aq7mr867935icc.49.1344720280592; Sat, 11 Aug 2012 14:24:40 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.200 with SMTP id ew8csp117548igc; Sat, 11 Aug 2012 14:24:39 -0700 (PDT) Received: by 10.14.220.70 with SMTP id n46mr3672968eep.42.1344720278664; Sat, 11 Aug 2012 14:24:38 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id l44si1597047eep.127.2012.08.11.14.24.37 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 11 Aug 2012 14:24:38 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1T0JAh-0006xn-Lc; Sat, 11 Aug 2012 22:24:35 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, qemu-trivial@nongnu.org, Michael Tokarev Subject: [PATCH] iov_send_recv(): Handle zero bytes case even if OS does not Date: Sat, 11 Aug 2012 22:24:35 +0100 Message-Id: <1344720275-26744-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQlZTGsvXkPeuqmVLMZeIEIpt4cTRraBLeRdXXBzCSt1j1480CIIvApRLHD6CXOpY8O1gGb/ POSIX allows sendmsg() and recvmsg() to fail EMSGSIZE if passed a zero msg.msg_iovlen (in particular the MacOS X implementation will do this). Handle the case where iov_send_recv() is passed a zero byte count explicitly, to avoid accidentally depending on the OS to treat zero msg_iovlen as a no-op. Signed-off-by: Peter Maydell Acked-by: Michael Tokarev --- This is what was causing 'make check' to fail on MacOS X. The other option was to declare that a zero bytecount was illegal, I guess. iov.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iov.c b/iov.c index b333061..60705c7 100644 --- a/iov.c +++ b/iov.c @@ -146,6 +146,13 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, { ssize_t ret; unsigned si, ei; /* start and end indexes */ + if (bytes == 0) { + /* Catch the do-nothing case early, as otherwise we will pass an + * empty iovec to sendmsg/recvmsg(), and not all implementations + * accept this. + */ + return 0; + } /* Find the start position, skipping `offset' bytes: * first, skip all full-sized vector elements, */