NetBSD Problem Report #49617

From www@NetBSD.org  Sat Jan 31 21:40:49 2015
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id D7FCFA6553
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 31 Jan 2015 21:40:49 +0000 (UTC)
Message-Id: <20150131214048.5EE91A6562@mollari.NetBSD.org>
Date: Sat, 31 Jan 2015 21:40:48 +0000 (UTC)
From: kirk@ba23.org
Reply-To: kirk@ba23.org
To: gnats-bugs@NetBSD.org
Subject: posix_fallocate() should be returning an error on failure, without setting errno.
X-Send-Pr-Version: www-1.0

>Number:         49617
>Category:       kern
>Synopsis:       posix_fallocate() should be returning an error on failure, without setting errno.
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 31 21:45:00 +0000 2015
>Closed-Date:    Wed Jun 01 01:16:19 +0000 2016
>Last-Modified:  Wed Jun 01 01:16:19 +0000 2016
>Originator:     Kirk Russell
>Release:        netbsd-7/201501202000Z
>Organization:
Bridlewood Software Testers Guild
>Environment:
NetBSD node53 7.0_BETA NetBSD 7.0_BETA (GENERIC.201501202000Z) i386
>Description:
The NetBSD-7 implementation of posix_fallocate() returns -1 and sets errno on failure.  The spec says the call should be returning an error number, without setting the errno.

http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_fallocate.html
>How-To-Repeat:
# atf-run t_posix_fallocate | atf-report
Tests root: /export/wsrc/cvs/src/tests/lib/libc/sys

t_posix_fallocate (1/1): 1 test cases
    ebadf: [0.083528s] Failed: Should return error Invalid argument without setting errno.
[0.137116s]

Failed test cases:
    t_posix_fallocate:ebadf

Summary for 1 test programs:
    0 passed test cases.
    1 failed test cases.
    0 expected failed test cases.
    0 skipped test cases.



--- /dev/null	2015-01-31 21:10:18.000000000 +0000
+++ tests/lib/libc/sys/t_posix_fallocate.c	2015-01-31 21:09:45.000000000 +0000
@@ -0,0 +1,61 @@
+/*-
+ * Copyright 2015, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *  * Neither the name of Google nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD$");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+ATF_TC_WITHOUT_HEAD(ebadf);
+ATF_TC_BODY(ebadf, tc)
+{
+	int rc, saved;
+
+	errno = 1111;
+	rc = posix_fallocate(-1, 0, 4096);
+	saved = errno;
+	if (rc == -1 && saved != 1111)
+		atf_tc_fail("Should return error %s without setting errno.",
+		    strerror(saved));
+	if (rc != EBADF)
+		atf_tc_fail("returned %s but expected %s.",
+		    strerror(saved), strerror(EBADF));
+	if (saved != 1111)
+		atf_tc_fail("errno should be %d but got changed to %d.",
+		    1111, saved);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, ebadf);
+	return atf_no_error();
+}

>Fix:

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49617 CVS commit: src/tests/lib/libc/sys
Date: Sat, 31 Jan 2015 18:06:57 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sat Jan 31 23:06:57 UTC 2015

 Modified Files:
 	src/tests/lib/libc/sys: Makefile
 Added Files:
 	src/tests/lib/libc/sys: t_posix_fallocate.c

 Log Message:
 PR/49617: Kirk Russell: posix_fallocate() should be returning an error on
 failure, without setting errno.


 To generate a diff of this commit:
 cvs rdiff -u -r1.36 -r1.37 src/tests/lib/libc/sys/Makefile
 cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_posix_fallocate.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49617 CVS commit: src/distrib/sets/lists
Date: Sat, 31 Jan 2015 18:09:27 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sat Jan 31 23:09:27 UTC 2015

 Modified Files:
 	src/distrib/sets/lists/debug: mi
 	src/distrib/sets/lists/tests: mi

 Log Message:
 PR/49617: Kirk Russell: new posix_fallocate test


 To generate a diff of this commit:
 cvs rdiff -u -r1.105 -r1.106 src/distrib/sets/lists/debug/mi
 cvs rdiff -u -r1.610 -r1.611 src/distrib/sets/lists/tests/mi

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49617 CVS commit: src/lib/libc/sys
Date: Sat, 31 Jan 2015 18:10:57 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sat Jan 31 23:10:57 UTC 2015

 Modified Files:
 	src/lib/libc/sys: Makefile.inc

 Log Message:
 PR/49617: Kirk Russell: posix_fallocate() should be returning an error on
 failure, without setting errno, so make it PSEUDO_NOERROR, by adding a new
 category GLUENOERR.


 To generate a diff of this commit:
 cvs rdiff -u -r1.226 -r1.227 src/lib/libc/sys/Makefile.inc

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: kirk russell <kirk@ba23.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/49617
Date: Sun, 1 Feb 2015 10:08:16 -0500

 Here is my draft man page changes for netbsd PR kern/49617:

 --- src/lib/libc/sys/fdiscard.2.orig 2014-07-25 08:47:42.000000000 +0000
 +++ src/lib/libc/sys/fdiscard.2 2015-02-01 14:57:39.000000000 +0000
 @@ -127,8 +127,16 @@
  may not be persistent after a crash or reboot if the space reserved
  has not yet been written to.
  .Sh RETURN VALUES
 -On success these calls return 0.
 -On error, \-1 is returned, and the global variable
 +If successful, the
 +.Fn posix_fallocate
 +function will return zero.
 +Otherwise an error number will be returned, without setting
 +.Va errno .
 +.Pp
 +If successful, the
 +.Fn fdiscard
 +function will return zero.
 +Otherwise the value \-1 is returned and the global variable
  .Va errno
  is set to indicate the error.
  .Sh ERRORS




 -- 
 Kirk Russell            <kirk@ba23.org>           http://www.ba23.org/

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49617 CVS commit: src/lib/libc/sys
Date: Sun, 1 Feb 2015 10:24:15 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sun Feb  1 15:24:15 UTC 2015

 Modified Files:
 	src/lib/libc/sys: fdiscard.2

 Log Message:
 PR/49617: Kirk Russell: Describe the posix_fallocate return values correctly.


 To generate a diff of this commit:
 cvs rdiff -u -r1.2 -r1.3 src/lib/libc/sys/fdiscard.2

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Soren Jacobsen" <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49617 CVS commit: [netbsd-7] src/lib/libc
Date: Sun, 8 Feb 2015 22:05:55 +0000

 Module Name:	src
 Committed By:	snj
 Date:		Sun Feb  8 22:05:55 UTC 2015

 Modified Files:
 	src/lib/libc/include [netbsd-7]: namespace.h
 	src/lib/libc/sys [netbsd-7]: Makefile.inc fdiscard.2
 Added Files:
 	src/lib/libc/sys [netbsd-7]: fdiscard.c posix_fallocate.c

 Log Message:
 Pull up following revision(s) (requested by christos in ticket #472):
 	lib/libc/include/namespace.h: revision 1.175
 	lib/libc/sys/Makefile.inc: revision 1.225, 1.227
 	lib/libc/sys/fdiscard.2: revision 1.3
 	lib/libc/sys/fdiscard.c: revision 1.1
 	lib/libc/sys/posix_fallocate.c: revision 1.1
 Fix argument paddiing for posix_fallocate and fdiscard with gcc 1.x
 --
 PR/49617: Kirk Russell: posix_fallocate() should be returning an error on
 failure, without setting errno, so make it PSEUDO_NOERROR, by adding a new
 category GLUENOERR.
 --
 PR/49617: Kirk Russell: Describe the posix_fallocate return values correctly.


 To generate a diff of this commit:
 cvs rdiff -u -r1.174 -r1.174.2.1 src/lib/libc/include/namespace.h
 cvs rdiff -u -r1.224 -r1.224.2.1 src/lib/libc/sys/Makefile.inc
 cvs rdiff -u -r1.2 -r1.2.4.1 src/lib/libc/sys/fdiscard.2
 cvs rdiff -u -r0 -r1.1.2.2 src/lib/libc/sys/fdiscard.c \
     src/lib/libc/sys/posix_fallocate.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/49617: posix_fallocate() should be returning an error on
 failure, without setting errno.
Date: Sun, 30 Aug 2015 19:26:24 +0000

 On Sat, Jan 31, 2015 at 09:45:00PM +0000, kirk@ba23.org wrote:
  > The NetBSD-7 implementation of posix_fallocate() returns -1 and
  > sets errno on failure.  The spec says the call should be returning
  > an error number, without setting the errno.

 Uuugh, sorry for not being aware of that.

 ISTM that this is a reason to have a native fallocate() that doesn't
 have this interface bug.

 -- 
 David A. Holland
 dholland@netbsd.org

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/49617: posix_fallocate() should be returning an error on failure, without setting errno.
Date: Sun, 30 Aug 2015 21:37:27 +0200

 On Sun, Aug 30, 2015 at 07:30:01PM +0000, David Holland wrote:
 >  ISTM that this is a reason to have a native fallocate() that doesn't
 >  have this interface bug.

 No, the posix_ prefix is hint enough and there is no information lost.

 Martin

State-Changed-From-To: open->closed
State-Changed-By: pgoyette@NetBSD.org
State-Changed-When: Wed, 01 Jun 2016 01:16:19 +0000
State-Changed-Why:
Bug fix and new atf test (and man page updates) were all committed.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.