From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Cc: Rich Felker <dalias@aerifal.cx>,
musl@lists.openwall.com, Isaac Dunham <idunham@lavabit.com>,
Paul Eggert <eggert@cs.ucla.edu>, Reuben Thomas <rrt@sc3d.org>
Subject: Re: grantpt test
Date: Fri, 22 Jun 2012 12:39:33 +0200 [thread overview]
Message-ID: <1502433.LbIKUIIHpc@linuix> (raw)
In-Reply-To: <20120620030445.GU163@brightrain.aerifal.cx>
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 <bruno@clisp.org>
grantpt: Relax requirement regarding invalid file descriptors.
* lib/grantpt.c: Don't include <fcntl.h>.
(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 <dalias@aerifal.cx>.
--- 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 <assert.h>
#include <errno.h>
-#include <fcntl.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -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;
next prev parent reply other threads:[~2012-06-22 10:39 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20120609230541.47eac2de@newbook>
[not found] ` <4FD55156.7050302@cs.ucla.edu>
[not found] ` <20120611182202.1ee4d019@newbook>
2012-06-17 22:49 ` musl bugs found through gnulib Bruno Haible
2012-06-17 23:54 ` Rich Felker
2012-06-18 8:21 ` Szabolcs Nagy
2012-06-18 13:02 ` John Spencer
2012-06-18 14:55 ` Rich Felker
2012-06-18 15:26 ` Szabolcs Nagy
2012-06-18 16:00 ` Rich Felker
2012-06-19 13:26 ` John Spencer
2012-06-18 0:16 ` [musl] " idunham
2012-06-19 0:11 ` Rich Felker
2012-06-19 2:07 ` [musl] " Eric Blake
2012-06-19 2:52 ` Rich Felker
2012-06-19 11:03 ` musl, fdopen test Bruno Haible
2012-06-19 11:09 ` Jim Meyering
2012-06-20 20:52 ` Bruno Haible
2012-06-19 10:45 ` musl, printf out-of-memory test Bruno Haible
2012-06-19 19:16 ` Rich Felker
2012-06-19 20:04 ` Bruno Haible
2012-06-19 20:08 ` Rich Felker
2012-06-19 21:17 ` Bruno Haible
2012-06-20 1:52 ` Rich Felker
2012-06-20 7:30 ` Szabolcs Nagy
2012-06-20 9:35 ` Bruno Haible
2012-06-20 11:00 ` Jim Meyering
2012-06-21 19:58 ` Tom Tromey
2012-06-20 3:04 ` Re: musl bugs found through gnulib Rich Felker
2012-06-20 4:10 ` [musl] " Eric Blake
2012-06-20 13:27 ` Rich Felker
2012-06-20 7:32 ` Szabolcs Nagy
2012-06-22 10:39 ` Bruno Haible [this message]
2012-07-02 22:33 ` [musl] " Pádraig Brady
2012-06-20 19:28 ` Rich Felker
2012-06-21 2:21 ` Rich Felker
2012-06-21 8:52 ` [musl] " Paul Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1502433.LbIKUIIHpc@linuix \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
--cc=dalias@aerifal.cx \
--cc=eggert@cs.ucla.edu \
--cc=idunham@lavabit.com \
--cc=musl@lists.openwall.com \
--cc=rrt@sc3d.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).