From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/1221 Path: news.gmane.org!not-for-mail From: Bruno Haible Newsgroups: gmane.linux.lib.musl.general,gmane.comp.lib.gnulib.bugs Subject: Re: grantpt test Date: Fri, 22 Jun 2012 12:39:33 +0200 Message-ID: <1502433.LbIKUIIHpc@linuix> References: <20120609230541.47eac2de@newbook> <12545931.v3ALTEUUx8@linuix> <20120620030445.GU163@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit X-Trace: dough.gmane.org 1340361476 26535 80.91.229.3 (22 Jun 2012 10:37:56 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 22 Jun 2012 10:37:56 +0000 (UTC) Cc: Rich Felker , musl@lists.openwall.com, Isaac Dunham , Paul Eggert , Reuben Thomas Bcc: bruno@haible.de To: bug-gnulib@gnu.org Original-X-From: musl-return-1222-gllmg-musl=m.gmane.org@lists.openwall.com Fri Jun 22 12:37:54 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Si1FO-0001D5-Jb for gllmg-musl@plane.gmane.org; Fri, 22 Jun 2012 12:37:50 +0200 Original-Received: (qmail 9871 invoked by uid 550); 22 Jun 2012 10:37:50 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9863 invoked from network); 22 Jun 2012 10:37:49 -0000 X-RZG-AUTH: :Ln4Re0+Ic/6oZXR1YgKryK8brksyK8dozXDwHXjf9hj/zDNRbvY44zMkpA== X-RZG-CLASS-ID: mo00 User-Agent: KMail/4.7.4 (Linux/3.1.10-1.9-desktop; KDE/4.7.4; x86_64; ; ) In-Reply-To: <20120620030445.GU163@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:1221 gmane.comp.lib.gnulib.bugs:31129 Archived-At: Rich Felker wrote: > > test-grantpt.c:34: assertion failed > > FAIL: test-grantpt > > This is an invalid test. POSIX specifies this function "may fail", not > "shall fail", and since the function is inherently a no-op, it would > be idiotic to make it perform a syscall to check the validity of the > file descriptor... Looking at the (few) callers of grantpt() in gnulib, it indeed seems unlikely that people will want to rely on the failure for invalid file descriptors. So I'm relaxing the requirements of gnulib. 2012-06-22 Bruno Haible grantpt: Relax requirement regarding invalid file descriptors. * lib/grantpt.c: Don't include . (grantpt): Don't verify the validity of the file descriptor. * modules/grantpt (Depends-on): Remove fcntl-h. * tests/test-grantpt.c (main): Allow grantpt to succeed for invalid file descriptors. * doc/posix-functions/grantpt.texi: Document more platforms on which grantpt succeeds for invalid file descriptors. Reported by Rich Felker . --- doc/posix-functions/grantpt.texi.orig Fri Jun 22 12:33:55 2012 +++ doc/posix-functions/grantpt.texi Fri Jun 22 12:33:52 2012 @@ -20,5 +20,5 @@ IRIX 5.3. @item This function reports success for invalid file descriptors on some platforms: -Cygwin 1.7.9. +OpenBSD, Cygwin 1.7.9, musl libc. @end itemize --- lib/grantpt.c.orig Fri Jun 22 12:33:55 2012 +++ lib/grantpt.c Fri Jun 22 12:14:57 2012 @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -50,8 +49,6 @@ #if defined __OpenBSD__ /* On OpenBSD, master and slave of a pseudo-terminal are allocated together, through an ioctl on /dev/ptm. There is no need for grantpt(). */ - if (fcntl (fd, F_GETFD) < 0) - return -1; return 0; #else /* This function is most often called from a process without 'root' --- modules/grantpt.orig Fri Jun 22 12:33:55 2012 +++ modules/grantpt Fri Jun 22 12:15:14 2012 @@ -9,7 +9,6 @@ Depends-on: stdlib extensions -fcntl-h [test $HAVE_GRANTPT = 0] pt_chown [test $HAVE_GRANTPT = 0] waitpid [test $HAVE_GRANTPT = 0] configmake [test $HAVE_GRANTPT = 0] --- tests/test-grantpt.c.orig Fri Jun 22 12:33:55 2012 +++ tests/test-grantpt.c Fri Jun 22 12:14:31 2012 @@ -28,22 +28,36 @@ int main (void) { - /* Test behaviour for invalid file descriptors. */ + /* Test behaviour for invalid file descriptors. + These calls don't fail on OpenBSD (with gnulib's replacement) and on + musl libc. */ { + int ret; + errno = 0; - ASSERT (grantpt (-1) == -1); - ASSERT (errno == EBADF - || errno == EINVAL /* seen on FreeBSD 6.4 */ - || errno == 0 /* seen on Solaris 8 */ - ); + ret = grantpt (-1); + if (ret != 0) + { + ASSERT (ret == -1); + ASSERT (errno == EBADF + || errno == EINVAL /* seen on FreeBSD 6.4 */ + || errno == 0 /* seen on Solaris 8 */ + ); + } } { + int ret; + errno = 0; - ASSERT (grantpt (99) == -1); - ASSERT (errno == EBADF - || errno == EINVAL /* seen on FreeBSD 6.4 */ - || errno == 0 /* seen on Solaris 8 */ - ); + ret = grantpt (99); + if (ret != 0) + { + ASSERT (ret == -1); + ASSERT (errno == EBADF + || errno == EINVAL /* seen on FreeBSD 6.4 */ + || errno == 0 /* seen on Solaris 8 */ + ); + } } return 0;