On Wed, 05 May 2004 10:32:04 -0700, Paul Eggert wrote: > Eric Sunshine <sunshine@xxxxxxxxxxxxxx> writes: > > I suppose it would require only a fairly minor change to _AS_RUN() > > to have it load the shell code from a file rather than standard > > input. I could submit a patch if it seems worthwhile(?). > It sounds like an easy patch, and if so could you please submit it? The included patch augments _AS_RUN so that it invokes the test from an external file rather than via the shell's standard input. -- ES 2004-05-20 Eric Sunshine <sunshine@xxxxxxxxxxxxxx> * m4sh.m4 (_AS_RUN): Run test code from external file rather than via shell's standard input in order to force non-interactive mode for csh shells. This resolves a near-pathalogical, yet real-world case where the shell test was fooled into thinking csh (or derivative) was a valid Bourne shell since some users 'exec /bin/sh' (or similar) at the end of .cshrc (or .tcshrc) when csh is run interactively. Relevant threads: http://mail.gnu.org/archive/html/autoconf/2004-05/msg00000.html http://mail.gnu.org/archive/html/bug-autoconf/2004-04/msg00072.html (AS_DETECT_REQUIRED): Do not invoke _AS_RUN for non-existent shells. (_AS_SHELL_FN_WORK): Use "test -eq" to check numeric result, rather than "test =". Correct botched diagnostic messages for failure of func_success() and func_failure() functions. --- /Users/sunshine/m4sh.m4-cvs Thu May 20 04:43:39 2004 +++ lib/m4sugar/m4sh.m4 Thu May 20 05:13:02 2004 @@ -168,18 +168,38 @@ ]) -# _AS_RUN(TEST, [SHELL]) -# ---------------------- +# _AS_RUN(TEST, [SHELL], [REDIRECT]) +# ---------------------------------- # Run TEST under the current shell (if one parameter is used) # or under the given SHELL, protecting it from syntax errors. +# Disposal of output and error messages from TEST is controlled by +# REDIRECT, which should consists of shell redirects. If not provided, +# then output and error messages are allowed to escape to stdout & stderr. +# +# We need to take special care if SHELL is csh or compatible. This might +# happen, for instance, when _AS_DETECT_BETTER_SHELL attempts $SHELL as a last +# resort. There is a near-pathalogical, yet real-world case where a user might +# 'exec' a different shell, such as /bin/sh or /bin/zsh, at the end of .cshrc +# (or .tcshrc) if csh is run in interactive mode. The "exec /bin/sh" will fool +# Autoconf into thinking that it is running a Bourne-like shell when it applies +# TEST despite the fact that the shell is actually a C-shell or derivative. To +# avoid this case, we must ensure that the shell is run in non-interactive +# mode. This is accomplished by feeding TEST to SHELL via a file (which forces +# non-interactive mode), rather than via SHELL's standard input (which places +# csh in the unwanted interactive mode). m4_define([_AS_RUN], [m4_ifval([$2], -[{ $2 <<\_ASEOF +[{ rm -f conf$$.sh +cat >conf$$.sh <<\_ASEOF _AS_BOURNE_COMPATIBLE $1 _ASEOF +$2 conf$$.sh +as_shellcode=$? +rm -f conf$$.sh +test $as_shellcode -eq 0 }], -[(eval "AS_ESCAPE(m4_quote($1))")])]) +[(eval "AS_ESCAPE(m4_quote($1))")]) m4_default([$3],[])]) # AS_DETECT_REQUIRED(TEST) # ------------------------ @@ -209,26 +229,27 @@ m4_defun_once([_AS_DETECT_BETTER_SHELL], [m4_wrap([m4_divert_text([M4SH-SANITIZE], [ if test "x$CONFIG_SHELL" = x; then - AS_IF([_AS_RUN([_AS_DETECT_REQUIRED_BODY]) 2>/dev/null], + AS_IF([_AS_RUN([_AS_DETECT_REQUIRED_BODY], [], [2>/dev/null 1>&2])], [as_have_required=yes], [as_have_required=no]) AS_IF([test $as_have_required = yes && dnl - _AS_RUN([_AS_DETECT_SUGGESTED_BODY]) 2> /dev/null], + _AS_RUN([_AS_DETECT_SUGGESTED_BODY], [], [2>/dev/null 1>&2])], [], [as_candidate_shells= _AS_PATH_WALK([/bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH], [case $as_dir in /*) for as_base in sh bash ksh sh5; do - as_candidate_shells="$as_candidate_shells $as_dir/$as_base" + AS_IF([test -f $as_dir/$as_base], + [as_candidate_shells="$as_candidate_shells $as_dir/$as_base"]) done esac]) for as_shell in $as_candidate_shells $SHELL; do - AS_IF([_AS_RUN([_AS_DETECT_REQUIRED_BODY], [$as_shell 2> /dev/null])], + AS_IF([_AS_RUN([_AS_DETECT_REQUIRED_BODY], [$as_shell], [2>/dev/null 1>&2])], [CONFIG_SHELL=$as_shell as_have_required=yes - AS_IF([_AS_RUN([_AS_DETECT_SUGGESTED_BODY], [$as_shell 2> /dev/null])], + AS_IF([_AS_RUN([_AS_DETECT_SUGGESTED_BODY], [$as_shell], [2>/dev/null 1>&2])], [break])]) done @@ -251,8 +272,7 @@ # _AS_SHELL_FN_WORK # ----------------- -# This is a spy to detect "in the wild" shells that do not support shell -# functions correctly. It is based on the m4sh.at Autotest testcases. +# Detect if the shell supports functions. m4_define([_AS_SHELL_FN_WORK], [func_return () { (exit [$]1) @@ -273,17 +293,17 @@ exitcode=0 AS_IF([func_success], [], [exitcode=1 - echo func_failure succeeded.]) + echo func_success failed.]) AS_IF([func_failure], [exitcode=1 - echo func_success failed.]) + echo func_failure succeeded.]) AS_IF([func_ret_success], [], [exitcode=1 echo func_ret_success failed.]) AS_IF([func_ret_failure], [exitcode=1 echo func_ret_failure succeeded.]) -test $exitcode = 0]) +test $exitcode -eq 0]) # AS_SHELL_SANITIZE @@ -1250,7 +1270,7 @@ _AS_RUN([_AS_SHELL_FN_WORK]) || { echo No shell found that supports shell functions. echo Please tell autoconf@xxxxxxx about your system, - echo including any error possibly output before this + echo possibly including any errors emitted before this echo message } ])