This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=8da33436aba118357c1f3145d10f439e41269a33

commit 8da33436aba118357c1f3145d10f439e41269a33
Author: Guillem Jover <[email protected]>
AuthorDate: Sun Oct 22 23:32:56 2023 +0200

    build: Handle almost-POSIX shells that do not support -- after -c
    
    At least the default sh on both FreeBSD and AIX do not support passing
    a -- after -c, so we check this at configure time, and disable its use
    in the code. This is not POSIX conformant but easy to workaround.
    
    Ref: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=274650
---
 lib/dpkg/command.c |  4 ++++
 m4/dpkg-progs.m4   | 25 +++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lib/dpkg/command.c b/lib/dpkg/command.c
index 36a155337..18c917b3c 100644
--- a/lib/dpkg/command.c
+++ b/lib/dpkg/command.c
@@ -208,7 +208,11 @@ command_shell(const char *cmd, const char *name)
        if (str_is_unset(shell))
                shell = DPKG_DEFAULT_SHELL;
 
+#if HAVE_DPKG_SHELL_WITH_DASH_DASH
        execlp(shell, shell, mode, "--", cmd, NULL);
+#else
+       execlp(shell, shell, mode, cmd, NULL);
+#endif
        ohshite(_("unable to execute %s (%s)"), name, cmd);
 }
 
diff --git a/m4/dpkg-progs.m4 b/m4/dpkg-progs.m4
index fd7f52074..2bb925702 100644
--- a/m4/dpkg-progs.m4
+++ b/m4/dpkg-progs.m4
@@ -5,16 +5,37 @@
 
 # DPKG_PROG_SHELL
 # ---------------
-# Locate a POSIX shell interpreter to use in dpkg.
+# Locate a POSIX shell interpreter to use in dpkg. It should support
+# passing -- after -c for robust argument parsing.
 AC_DEFUN([DPKG_PROG_SHELL], [
   AC_ARG_VAR([DPKG_SHELL], [default POSIX shell interpreter used by dpkg])
-  AS_IF([test -z "$DPKG_SHELL"], [
+  AC_CACHE_CHECK([for a POSIX sh that supports -- after -c], 
[ac_cv_path_DPKG_SHELL], [
+    AC_PATH_PROGS_FEATURE_CHECK([DPKG_SHELL], [sh dash bsh ksh bash], [
+      shellcheck=$(test -x $ac_path_DPKG_SHELL && \
+        $ac_path_DPKG_SHELL -c -- "echo yes" 2>/dev/null)
+      AS_IF([test "x$shellcheck" = "xyes"], [
+        ac_cv_path_DPKG_SHELL="$(AS_BASENAME([$ac_path_DPKG_SHELL]))"
+        ac_path_DPKG_SHELL_found=:
+      ])
+    ], [
+      ac_cv_path_DPKG_SHELL=none
+    ])
+  ])
+  dnl We could not find any shell supporting --, fallback to sh.
+  AS_IF([test "$ac_cv_path_DPKG_SHELL" = "none"], [
     DPKG_SHELL=sh
+    dpkg_shell_supports_dash_dash=0
+  ], [
+    DPKG_SHELL=$ac_cv_path_DPKG_SHELL
+    dpkg_shell_supports_dash_dash=1
   ])
 
   AC_SUBST([DPKG_DEFAULT_SHELL], [$DPKG_SHELL])
   AC_DEFINE_UNQUOTED([DPKG_DEFAULT_SHELL], ["$DPKG_SHELL"],
     [POSIX shell interpreter used by dpkg])
+  AC_DEFINE_UNQUOTED([HAVE_DPKG_SHELL_WITH_DASH_DASH],
+    [$dpkg_shell_supports_dash_dash],
+    [POSIX shell interpreter used by dpkg supports -- after -c])
 ])# DPKG_PROG_SHELL
 
 # DPKG_PROG_PAGER

-- 
Dpkg.Org's dpkg

Reply via email to