]> Savannah Git Hosting - gnulib.git/commitdiff
getusershell: Work around musl bugs.
authorCollin Funk <collin.funk1@gmail.com>
Sun, 19 May 2024 23:40:34 +0000 (16:40 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Sun, 19 May 2024 23:40:34 +0000 (16:40 -0700)
Reported by Bruno Haible in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-05/msg00261.html>.

* doc/glibc-functions/getusershell.texi: Mention the musl bug.
* lib/unistd.in.h (getusershell, setusershell, endusershell): Allow the
functions to be declared with the rpl_ prefix.
* m4/getusershell.m4 (gl_FUNC_GETUSERSHELL): Prepare functions to be
replaced on musl systems.
(gl_PREREQ_GETUSERSHELL): New macro.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize
REPLACE_GETUSERSHELL.
* modules/getusershell (Depends-on): Update module conditions to account
for the function being available but replaced by Gnulib.
(configure.ac): Likewise. Invoke gl_PREREQ_GETUSERSHELL.

ChangeLog
doc/glibc-functions/getusershell.texi
lib/unistd.in.h
m4/getusershell.m4
m4/unistd_h.m4
modules/getusershell
modules/unistd

index 1e8cc9405421848de3442fb503876c1bf61d35c8..89c5aa69938a7c8a77d56bc74c65120b6dc267b9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2024-05-19  Collin Funk  <collin.funk1@gmail.com>
+
+       getusershell: Work around musl bugs.
+       Reported by Bruno Haible in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2024-05/msg00261.html>.
+       * doc/glibc-functions/getusershell.texi: Mention the musl bug.
+       * lib/unistd.in.h (getusershell, setusershell, endusershell): Allow the
+       functions to be declared with the rpl_ prefix.
+       * m4/getusershell.m4 (gl_FUNC_GETUSERSHELL): Prepare functions to be
+       replaced on musl systems.
+       (gl_PREREQ_GETUSERSHELL): New macro.
+       * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize
+       REPLACE_GETUSERSHELL.
+       * modules/getusershell (Depends-on): Update module conditions to account
+       for the function being available but replaced by Gnulib.
+       (configure.ac): Likewise. Invoke gl_PREREQ_GETUSERSHELL.
+
 2024-05-18  Bruno Haible  <bruno@clisp.org>
 
        abort-debug: Prefer libbacktrace to execinfo.
index 83b6d4971ef769c7453229669988da0e53b0706b..379e6d893f59265345ae56bfffa1fce3a0f5a74f 100644 (file)
@@ -14,6 +14,11 @@ Minix 3.1.8, mingw, MSVC 14, Android 9.0.
 @item
 This function is missing a declaration on some platforms:
 Solaris 9.
+
+@item
+This function mistakenly returns comments and empty lines on some platforms:
+@c https://www.openwall.com/lists/musl/2024/05/18/1
+musl libc 1.2.4
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 7dbed38969b4a08e45a09a8d99c59d1b86a326ea..e01629af259dfc87892c230b30d78b30f13a34b8 100644 (file)
@@ -1531,12 +1531,21 @@ _GL_CXXALIASWARN (getpid);
 
 
 #if @GNULIB_GETUSERSHELL@
+# if @REPLACE_GETUSERSHELL@
 /* Return the next valid login shell on the system, or NULL when the end of
    the list has been reached.  */
-# if !@HAVE_DECL_GETUSERSHELL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef getusershell
+#    define getusershell rpl_getusershell
+#  endif
+_GL_FUNCDECL_RPL (getusershell, char *, (void));
+_GL_CXXALIAS_RPL (getusershell, char *, (void));
+# else
+#  if !@HAVE_DECL_GETUSERSHELL@
 _GL_FUNCDECL_SYS (getusershell, char *, (void));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (getusershell, char *, (void));
+# endif
 _GL_CXXALIASWARN (getusershell);
 #elif defined GNULIB_POSIXCHECK
 # undef getusershell
@@ -1548,10 +1557,19 @@ _GL_WARN_ON_USE (getusershell, "getusershell is unportable - "
 
 #if @GNULIB_GETUSERSHELL@
 /* Rewind to pointer that is advanced at each getusershell() call.  */
-# if !@HAVE_DECL_GETUSERSHELL@
+# if @REPLACE_GETUSERSHELL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef setusershell
+#    define setusershell rpl_setusershell
+#  endif
+_GL_FUNCDECL_RPL (setusershell, void, (void));
+_GL_CXXALIAS_RPL (setusershell, void, (void));
+# else
+#  if !@HAVE_DECL_GETUSERSHELL@
 _GL_FUNCDECL_SYS (setusershell, void, (void));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (setusershell, void, (void));
+# endif
 _GL_CXXALIASWARN (setusershell);
 #elif defined GNULIB_POSIXCHECK
 # undef setusershell
@@ -1564,10 +1582,19 @@ _GL_WARN_ON_USE (setusershell, "setusershell is unportable - "
 #if @GNULIB_GETUSERSHELL@
 /* Free the pointer that is advanced at each getusershell() call and
    associated resources.  */
-# if !@HAVE_DECL_GETUSERSHELL@
+# if @REPLACE_GETUSERSHELL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef endusershell
+#    define endusershell rpl_endusershell
+#  endif
+_GL_FUNCDECL_RPL (endusershell, void, (void));
+_GL_CXXALIAS_RPL (endusershell, void, (void));
+# else
+#  if !@HAVE_DECL_GETUSERSHELL@
 _GL_FUNCDECL_SYS (endusershell, void, (void));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (endusershell, void, (void));
+# endif
 _GL_CXXALIASWARN (endusershell);
 #elif defined GNULIB_POSIXCHECK
 # undef endusershell
index e4ed3f6593858a54f72e31084ddd8cca9f00f835..f834151c7db916df5970daf9e78dec70dc8a02a0 100644 (file)
@@ -1,5 +1,5 @@
 # getusershell.m4
-# serial 7
+# serial 8
 dnl Copyright (C) 2002-2003, 2006, 2008-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,6 +8,7 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_FUNC_GETUSERSHELL],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
 
   dnl Persuade glibc <unistd.h> to declare {get,set,end}usershell().
   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
@@ -26,4 +27,12 @@ AC_DEFUN([gl_FUNC_GETUSERSHELL],
     dnl Assume that on platforms which declare it, the function exists.
     HAVE_DECL_GETUSERSHELL=0
   fi
+  dnl Replace the function on musl unconditionally.
+  dnl See: https://www.openwall.com/lists/musl/2024/05/18/1
+  case "$host_os" in
+    *-musl* | midipix*) REPLACE_GETUSERSHELL=1 ;;
+  esac
 ])
+
+# Prerequisites of lib/getusershell.c.
+AC_DEFUN([gl_PREREQ_GETUSERSHELL], [:])
index 81d1b9f6169dd091531e57305187142457920baa..04fa79c9ca607712b181b7ea2f5fb50feabeded4 100644 (file)
@@ -1,5 +1,5 @@
 # unistd_h.m4
-# serial 95
+# serial 96
 dnl Copyright (C) 2006-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -248,6 +248,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   REPLACE_GETPAGESIZE=0;             AC_SUBST([REPLACE_GETPAGESIZE])
   REPLACE_GETPASS=0;                 AC_SUBST([REPLACE_GETPASS])
   REPLACE_GETPASS_FOR_GETPASS_GNU=0; AC_SUBST([REPLACE_GETPASS_FOR_GETPASS_GNU])
+  REPLACE_GETUSERSHELL=0;            AC_SUBST([REPLACE_GETUSERSHELL])
   REPLACE_ISATTY=0;                  AC_SUBST([REPLACE_ISATTY])
   REPLACE_LCHOWN=0;                  AC_SUBST([REPLACE_LCHOWN])
   REPLACE_LINK=0;                    AC_SUBST([REPLACE_LINK])
index 19929c9b2ceeccc17de13615d2e4970496321596..2f47c62e3df826303d8045142fa48dd55de164e4 100644 (file)
@@ -8,13 +8,17 @@ m4/getusershell.m4
 Depends-on:
 unistd
 extensions
-fopen-safer          [test $HAVE_GETUSERSHELL = 0]
-unlocked-io-internal [test $HAVE_GETUSERSHELL = 0]
-xalloc               [test $HAVE_GETUSERSHELL = 0]
+fopen-safer          [test $HAVE_GETUSERSHELL = 0 || test $REPLACE_GETUSERSHELL = 1]
+unlocked-io-internal [test $HAVE_GETUSERSHELL = 0 || test $REPLACE_GETUSERSHELL = 1]
+xalloc               [test $HAVE_GETUSERSHELL = 0 || test $REPLACE_GETUSERSHELL = 1]
 
 configure.ac:
 gl_FUNC_GETUSERSHELL
-gl_CONDITIONAL([GL_COND_OBJ_GETUSERSHELL], [test $HAVE_GETUSERSHELL = 0])
+gl_CONDITIONAL([GL_COND_OBJ_GETUSERSHELL],
+               [test $HAVE_GETUSERSHELL = 0 || test $REPLACE_GETUSERSHELL = 1])
+AM_COND_IF([GL_COND_OBJ_GETUSERSHELL], [
+  gl_PREREQ_GETUSERSHELL
+])
 gl_UNISTD_MODULE_INDICATOR([getusershell])
 
 Makefile.am:
index ce2ee04edc9181a4da54bfe6cd5b7fcdccefe2e9..f3c84660c346b9ab6347938a96a438a707f3931f 100644 (file)
@@ -205,6 +205,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
              -e 's|@''REPLACE_GETPASS''@|$(REPLACE_GETPASS)|g' \
              -e 's|@''REPLACE_GETPASS_FOR_GETPASS_GNU''@|$(REPLACE_GETPASS_FOR_GETPASS_GNU)|g' \
+             -e 's|@''REPLACE_GETUSERSHELL''@|$(REPLACE_GETUSERSHELL)|g' \
              -e 's|@''REPLACE_ISATTY''@|$(REPLACE_ISATTY)|g' \
              -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
              -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \