From owner-freebsd-standards@FreeBSD.ORG Fri Jan 24 18:12:54 2014 Return-Path: Delivered-To: standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 79E4EAD9; Fri, 24 Jan 2014 18:12:54 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7728D1A70; Fri, 24 Jan 2014 18:12:52 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.7/8.14.7) with ESMTP id s0OICk9D070612; Fri, 24 Jan 2014 20:12:46 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua s0OICk9D070612 Received: (from kostik@localhost) by tom.home (8.14.7/8.14.7/Submit) id s0OICk5g070611; Fri, 24 Jan 2014 20:12:46 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 24 Jan 2014 20:12:46 +0200 From: Konstantin Belousov To: Bob Bishop Subject: Re: standards/186028: incorrect return values for posix_fallocate() Message-ID: <20140124181246.GO24664@kib.kiev.ua> References: <201401230858.s0N8wwQB039907@oldred.freebsd.org> <20140123094017.GH24664@kib.kiev.ua> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="gh4H09KImyIEQ1se" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.22 (2013-10-16) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: Gennady Proskurin , mdf@freebsd.org, standards@freebsd.org, jhb@freebsd.org X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jan 2014 18:12:54 -0000 --gh4H09KImyIEQ1se Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jan 23, 2014 at 09:20:11PM +0000, Bob Bishop wrote: > Hi, >=20 > On 23 Jan 2014, at 09:40, Konstantin Belousov wrote: >=20 > > On Thu, Jan 23, 2014 at 08:58:58AM +0000, Gennady Proskurin wrote: > >>=20 > >>> Number: 186028 > >>> Category: standards > >>> Synopsis: incorrect return values for posix_fallocate() > >>> Confidential: no > >>> Severity: non-critical > >>> Priority: low > >>> Responsible: freebsd-standards > >>> State: open > >>> Quarter: =20 > >>> Keywords: =20 > >>> Date-Required: > >>> Class: sw-bug > >>> Submitter-Id: current-users > >>> Arrival-Date: Thu Jan 23 09:00:00 UTC 2014 > >>> Closed-Date: > >>> Last-Modified: > >>> Originator: Gennady Proskurin > >>> Release: FreeBSD 11.0-CURRENT > >>> Organization: > >>> Environment: > >> FreeBSD gpr.nnz-home.ru 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r260472+7= 43aa78(svn_head): Fri Jan 10 05:28:05 MSK 2014 gpr@gpr.nnz-home.ru:/usr= /obj/usr/src/freebsd-head/sys/GPR amd64 > >>> Description: > >> In case of error, posix_fallocate() should return error code itself, b= ut in FreeBSD it returns -1 and sets errno. >=20 > FWIW at least posix_madvise() and posix_fadvise() have the same problem. Indeed, I suppose the following should also fix two syscalls noted. I hope that some doc committer would do the pass over man pages following Bruce' suggestions. diff --git a/lib/libc/gen/pmadvise.c b/lib/libc/gen/pmadvise.c index 60cef63..68b1181 100644 --- a/lib/libc/gen/pmadvise.c +++ b/lib/libc/gen/pmadvise.c @@ -12,5 +12,14 @@ __FBSDID("$FreeBSD$"); int posix_madvise(void *address, size_t size, int how) { - return madvise(address, size, how); + int ret, saved_errno; + + saved_errno =3D errno; + if (madvise(address, size, how) =3D=3D -1) { + ret =3D errno; + errno =3D saved_errno; + } else { + ret =3D 0; + } + return (ret); } diff --git a/lib/libc/sys/madvise.2 b/lib/libc/sys/madvise.2 index b5ea6b2..755ecc2 100644 --- a/lib/libc/sys/madvise.2 +++ b/lib/libc/sys/madvise.2 @@ -50,7 +50,10 @@ allows a process that has knowledge of its memory behavi= or to describe it to the system. The .Fn posix_madvise -interface is identical and is provided for standards conformance. +interface is identical, except it returns an error number on error and does +not modify +.Va errno , +and is provided for standards conformance. .Pp The known behaviors are: .Bl -tag -width MADV_SEQUENTIAL diff --git a/lib/libc/sys/posix_fadvise.2 b/lib/libc/sys/posix_fadvise.2 index 7a9a648..96c99d2 100644 --- a/lib/libc/sys/posix_fadvise.2 +++ b/lib/libc/sys/posix_fadvise.2 @@ -93,7 +93,7 @@ Future access to this data may require a read operation. .Sh ERRORS The .Fn posix_fadvise -system call will fail if: +system call returns zero on success, and an error on failure: .Bl -tag -width Er .It Bq Er EBADF The diff --git a/lib/libc/sys/posix_fallocate.2 b/lib/libc/sys/posix_fallocate.2 index 1460764..7501777 100644 --- a/lib/libc/sys/posix_fallocate.2 +++ b/lib/libc/sys/posix_fallocate.2 @@ -83,9 +83,8 @@ that reduces the file size to a size smaller than If successful, .Fn posix_fallocate returns zero. -It returns error number on failure, without setting -.Va errno -variable. +It returns an error on failure, without setting +.Va errno . .Sh ERRORS Possible failure conditions: .Bl -tag -width Er diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/f= reebsd32_misc.c index e4ffbe4..c7b677f 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -3005,8 +3005,10 @@ freebsd32_posix_fadvise(struct thread *td, struct freebsd32_posix_fadvise_args *uap) { =20 - return (kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset), - PAIR32TO64(off_t, uap->len), uap->advice)); + td->td_retval[0] =3D kern_posix_fadvise(td, uap->fd, + PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len), + uap->advice); + return (0); } =20 int diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index b864c90..4be9738 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -4725,6 +4725,7 @@ int sys_posix_fadvise(struct thread *td, struct posix_fadvise_args *uap) { =20 - return (kern_posix_fadvise(td, uap->fd, uap->offset, uap->len, - uap->advice)); + td->td_retval[0] =3D kern_posix_fadvise(td, uap->fd, uap->offset, + uap->len, uap->advice); + return (0); } --gh4H09KImyIEQ1se Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iQIcBAEBAgAGBQJS4q0dAAoJEJDCuSvBvK1BKz8P/AgpeU9JoVbVt3xLHOwOgu0Z 2kXxFPCViJR/R0ZOsaZSrmKRPbFTnkkyPLCDuRZ6yExznRxwUlLc0nMauEa/+wmx 0eJUeIuoNAY6JgayvqJyaH9RK+K9UEKwQInOfUcFKPwDTH4qq3eY//EoJfvW8Ds2 fm32RRXWMoMRoBHxeYp15am0zmMJ3LluhWZ9dEp53s1qYNkZkvJDoA1ikNK2Ndnp lX17+UFq8LpOZB0dTHDhM2whsGuKu0NjnF2cLs/W26xq1Spyf+f4D2tg3hiFeNuB hc7h1W+Ygm9LvtqUY9NTxYQrG9UtF0xUMd0jX1N57KAO51a5d9Ph+r+YVM5zBJ8i 1KYz3/1/gdzOzDzpRoeQ79uKg5MQpVdJfYuSj5qgOzC2N6UUsC7Q1XIM9ygmJLSs aR03lkwjMy5RJTTT0hWB12NVfoF66OdrXve0p7WkYTAanSd1AQxoI4S4XG4POKle AIlQ27jAvWK0G7dl5ZoOeYL3FzWZTLrZ4twTddHPiN3shwH+//ZoNdwQoxYdnzAJ 9zI0LTlAbQ5p/GzKC5+IfUiQXwfj+odaZh39vlpddnkNEz9uPrKqs1MRbVA0LEmz ifAPFdg9RhxTokeo1B5Pq/TKQcosGXKhmOsEIV3ACBh9digQRnjJ3HMtMBwsAR+o ka6fY74p6Q0YrTv/xlMw =EtIo -----END PGP SIGNATURE----- --gh4H09KImyIEQ1se--