Re: openat-safer: Avoid test failure on NetBSD 8

2018-12-15 Thread Jim Meyering
On Sat, Dec 15, 2018 at 3:50 PM Bruno Haible  wrote:
> While testing a grep snapshot on NetBSD 8, I see that the gnulib test
> 'test-openat-safer' fails:
>
> FAIL: test-openat-safer
> ===
>
> ../../gnulib-tests/test-openat-safer.c:101: assertion 'STDERR_FILENO < fd' 
> failed
> FAIL test-openat-safer (exit status: 134)
>
>
> The reason is that the test is too strong: It verifies that
> "Using a bad directory is okay for absolute paths". But this is not guaranteed
> by POSIX [1] (as far as I understand it). Only the Linux man page specifies
> this [2].
>
> So let's conditionalize this test.
>
> [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
> [2] https://linux.die.net/man/2/openat
>
> 2018-12-15  Bruno Haible  
>
> openat-safer tests: Avoid test failure on NetBSD 8.
> * tests/test-openat-safer.c (main): Execute a Linux specific test only
> on Linux.

Looks fine to me. Thank you, Bruno.



openat-safer: Avoid test failure on NetBSD 8

2018-12-15 Thread Bruno Haible
While testing a grep snapshot on NetBSD 8, I see that the gnulib test
'test-openat-safer' fails:

FAIL: test-openat-safer
===

../../gnulib-tests/test-openat-safer.c:101: assertion 'STDERR_FILENO < fd' 
failed
FAIL test-openat-safer (exit status: 134)


The reason is that the test is too strong: It verifies that
"Using a bad directory is okay for absolute paths". But this is not guaranteed
by POSIX [1] (as far as I understand it). Only the Linux man page specifies
this [2].

So let's conditionalize this test.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
[2] https://linux.die.net/man/2/openat


2018-12-15  Bruno Haible  

    openat-safer tests: Avoid test failure on NetBSD 8.
* tests/test-openat-safer.c (main): Execute a Linux specific test only
on Linux.

diff --git a/tests/test-openat-safer.c b/tests/test-openat-safer.c
index e8977e4..4711a8e 100644
--- a/tests/test-openat-safer.c
+++ b/tests/test-openat-safer.c
@@ -96,11 +96,15 @@ main (void)
   errno = 0;
   ASSERT (openat (dfd, witness "/", O_RDONLY) == -1);
   ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL);
+#ifdef __linux__
   /* Using a bad directory is okay for absolute paths.  */
   fd = openat (-1, "/dev/null", O_WRONLY);
   ASSERT (STDERR_FILENO < fd);
+#endif
   /* Using a non-directory is wrong for relative paths.  */
   errno = 0;
+  fd = open ("/dev/null", O_RDONLY);
+  ASSERT (STDERR_FILENO < fd);
   ASSERT (openat (fd, ".", O_RDONLY) == -1);
   ASSERT (errno == EBADF || errno == ENOTDIR);
   ASSERT (close (fd) == 0);