Grisha Levit wrote:
> FWIW, Austin Group Defect 418 [1] seems directly on point and in line with
> your interpretation.
> 
> [1] posix_spawn_file_actions_addclose() should not check against OPEN_MAX
>     https://austingroupbugs.net/view.php?id=418

Thanks for this reference. So, it was wrong that I wanted to make the
function behave on NetBSD like on glibc. I'm reverting that change now.

> > Hi Bruno, any thoughts on this? I'm considering opening a glibc bug
> > report for it. But it would be nice to get another interpretation,
> > whether or not it agrees with mine.

The Rationale section of
https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_spawn_file_actions_addclose.html
explains the logic. Whether it's a glibc bug depends whether in glibc
"{OPEN_MAX} reflects the RLIMIT_NOFILE soft limit"; I haven't looked
how sysconf (_SC_OPEN_MAX) is implemented in glibc.

> P.S. All of the BSD spawn implementations are roughly the same. OpenBSD
> and NetBSD used FreeBSD's implementation.

I saw the
  checking whether posix_spawn_file_actions_addclose works... no
configure result only on musl libc, NetBSD, Cygwin. On FreeBSD and OpenBSD
this configure test is not being executed.


2025-10-31  Bruno Haible  <[email protected]>

        posix_spawn_file_actions_addclose: Ignore test failure on NetBSD 10.0.
        Based on comments by Collin Funk and Grisha Levit.
        * m4/posix_spawn.m4 (gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE): Revert
        last change.
        * tests/test-posix_spawn_file_actions_addclose.c (main): Treat NetBSD
        like musl and Cygwin.
        * doc/posix-functions/posix_spawn_file_actions_addclose.texi: Document
        the large fd bug as "not fixed".

diff --git a/doc/posix-functions/posix_spawn_file_actions_addclose.texi 
b/doc/posix-functions/posix_spawn_file_actions_addclose.texi
index 12ac6e9514..80c20b8681 100644
--- a/doc/posix-functions/posix_spawn_file_actions_addclose.texi
+++ b/doc/posix-functions/posix_spawn_file_actions_addclose.texi
@@ -15,11 +15,12 @@
 @item
 This function does not reject a negative file descriptor on some platforms:
 musl libc.
-@item
-This function does not reject an out-of-range file descriptor on some 
platforms:
-NetBSD.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
+@item
+This function does not reject an out-of-range file descriptor on some 
platforms:
+@c https://austingroupbugs.net/view.php?id=418
+musl libc, NetBSD, Cygwin.
 @end itemize
diff --git a/m4/posix_spawn.m4 b/m4/posix_spawn.m4
index 4c1f755f37..8b9d6d6d67 100644
--- a/m4/posix_spawn.m4
+++ b/m4/posix_spawn.m4
@@ -1,5 +1,5 @@
 # posix_spawn.m4
-# serial 26
+# serial 27
 dnl Copyright (C) 2008-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -571,8 +571,6 @@ AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE]
   else
     dnl On musl libc, posix_spawn_file_actions_addclose succeeds even if the fd
     dnl argument is negative.
-    dnl On NetBSD 10.0, posix_spawn_file_actions_addclose succeeds even if the
-    dnl fd argument is out of range.
     AC_CACHE_CHECK([whether posix_spawn_file_actions_addclose works],
       [gl_cv_func_posix_spawn_file_actions_addclose_works],
       [AC_RUN_IFELSE(
@@ -585,16 +583,13 @@ AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE]
     return 1;
   if (posix_spawn_file_actions_addclose (&actions, -5) == 0)
     return 2;
-  if (posix_spawn_file_actions_addclose (&actions, 10000000) == 0)
-    return 3;
   return 0;
 }]])],
          [gl_cv_func_posix_spawn_file_actions_addclose_works=yes],
          [gl_cv_func_posix_spawn_file_actions_addclose_works=no],
-         [# Guess no on musl libc and NetBSD and Solaris, yes otherwise.
+         [# Guess no on musl libc and Solaris, yes otherwise.
           case "$host_os" in
             *-musl* | midipix*) 
gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;;
-            netbsd*)            
gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;;
             solaris*)           
gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;;
                                 # Guess no on native Windows.
             mingw* | windows*)  
gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;;
diff --git a/tests/test-posix_spawn_file_actions_addclose.c 
b/tests/test-posix_spawn_file_actions_addclose.c
index 359503c4af..dd88c4eecc 100644
--- a/tests/test-posix_spawn_file_actions_addclose.c
+++ b/tests/test-posix_spawn_file_actions_addclose.c
@@ -54,9 +54,10 @@ main (void)
     errno = 0;
     ASSERT (posix_spawn_file_actions_addclose (&actions, -1) == EBADF);
   }
-  /* This behaviour is not mandated by POSIX, but happens to pass on all
-     platforms except musl libc and Cygwin.  */
-#if !(defined MUSL_LIBC || defined __CYGWIN__)
+  /* This behaviour is not mandated by POSIX, following
+     <https://austingroupbugs.net/view.php?id=418>,
+     but happens to pass on all platforms except musl libc, NetBSD, Cygwin.  */
+#if !(defined MUSL_LIBC || defined __NetBSD__ || defined __CYGWIN__)
   {
     int bad_fd = big_fd ();
     errno = 0;




Reply via email to