From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XF0N8-00075Y-8I for qemu-devel@nongnu.org; Wed, 06 Aug 2014 08:31:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XF0N3-0003WL-FO for qemu-devel@nongnu.org; Wed, 06 Aug 2014 08:31:14 -0400 Received: from mx3-phx2.redhat.com ([209.132.183.24]:46792) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XF0N3-0003Th-8b for qemu-devel@nongnu.org; Wed, 06 Aug 2014 08:31:09 -0400 Date: Wed, 6 Aug 2014 08:30:55 -0400 (EDT) From: Levente Kurusa Message-ID: <889919637.11247423.1407328255674.JavaMail.zimbra@redhat.com> In-Reply-To: <1407305758-13108-5-git-send-email-zhang.zhanghailiang@huawei.com> References: <1407305758-13108-1-git-send-email-zhang.zhanghailiang@huawei.com> <1407305758-13108-5-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 4/4] ivshmem: check the value returned by fstat() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: zhanghailiang Cc: kwolf@redhat.com, alex@alex.org.uk, mst@redhat.com, luonengjun@huawei.com, peter huangpeng , qemu-devel@nongnu.org, stefanha@redhat.com, pbonzini@redhat.com, lcapitulino@redhat.com, alex bennee > The function fstat() may fail, so check its return value. > > Signed-off-by: zhanghailiang > --- > hw/misc/ivshmem.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c > index 768e528..5d939d2 100644 > --- a/hw/misc/ivshmem.c > +++ b/hw/misc/ivshmem.c > @@ -324,7 +324,11 @@ static int check_shm_size(IVShmemState *s, int fd) { > > struct stat buf; > > - fstat(fd, &buf); > + if (fstat(fd, &buf) < 0) { > + fprintf(stderr, "ivshmem: exiting for fstat fd '%d' failed: %s\n", > + fd, strerror(errno)); exiting for fstat? I would go with something like this: "ivshmem: exiting: fstat on fd %d failed: %s" ... or something among the lines. Thanks! Levente Kurusa