From 979fcdc4cfe76c0df7e3ec6450df03a366e5f3b7 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 2 Mar 2009 15:08:31 -0700 Subject: Allow configuration choice in syscmd shell. * ltdl/m4/m4-syscmd.m4: New file. * configure.ac (M4_SYSCMD): Use it to provide --with-syscmd-shell. (AC_CHECK_HEADERS_ONCE): No longer need to worry about . * modules/m4.c (syscmd): Use it to avoid hard-coding the shell location. * modules/gnu.c (esyscmd): Likewise. * doc/m4.texinfo (Syscmd, Esyscmd): Document this. * README: Document new configure option. * NEWS: Likewise. Signed-off-by: Eric Blake (cherry picked from commit 060b5319b3452a2464eea1defc5fae608a12b574) --- ChangeLog | 13 ++++++++++++ NEWS | 3 +++ README | 9 +++++++- configure.ac | 13 ++++++++---- doc/m4.texinfo | 18 ++++++++++++++++ ltdl/m4/m4-syscmd.m4 | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ modules/gnu.c | 13 ++++++------ modules/m4.c | 13 ++++++------ 8 files changed, 122 insertions(+), 19 deletions(-) create mode 100644 ltdl/m4/m4-syscmd.m4 diff --git a/ChangeLog b/ChangeLog index b5f6487a..30f1c16e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2009-03-13 Eric Blake + Allow configuration choice in syscmd shell. + * ltdl/m4/m4-syscmd.m4: New file. + * configure.ac (M4_SYSCMD): Use it to provide + --with-syscmd-shell. + (AC_CHECK_HEADERS_ONCE): No longer need to worry about + . + * modules/m4.c (syscmd): Use it to avoid hard-coding the shell + location. + * modules/gnu.c (esyscmd): Likewise. + * doc/m4.texinfo (Syscmd, Esyscmd): Document this. + * README: Document new configure option. + * NEWS: Likewise. + Use gnulib pipe module instead of popen(3). * ltdl/m4/gnulib-cache.m4: Import pipe and wait-process modules. * modules/gnu.c (M4_SYSVAL_EXITBITS, M4_SYSVAL_TERMSIGBITS): diff --git a/NEWS b/NEWS index d2d42b54..4c6a76a7 100644 --- a/NEWS +++ b/NEWS @@ -355,6 +355,9 @@ contains the following beta features that were deemed worth deferring until `m4 --debugfile=trace file', not `m4 file --debugfile trace'. This change does not affect the deprecated `-o'/`--error-output' option. +** The `syscmd' and `esyscmd' builtins can be configured to use an + alternate shell, via the new `configure' option `--with-syscmd-shell'. + ** A number of portability improvements inherited from gnulib. * Noteworthy changes in Version 1.4.12 (2008-10-10) [stable] diff --git a/README b/README index 390de384..a128a02c 100644 --- a/README +++ b/README @@ -44,6 +44,12 @@ host architecture. The implementation uses libltdl interface, details of which are in the libtool manual. See file `modules/README' for a more detailed description. +By default, the `syscmd' and `esyscmd' macros try to use the first +instance of `sh' found by `command -p getconf PATH' at configure time, +with a default of `/bin/sh'. If that default is inappropriate, you +can use `./configure --with-syscmd-shell=location' to specify the +shell to use. + By using `./configure --with-dmalloc', GNU m4 is linked with Gray Watson's dmalloc package. It is a debugging option for finding memory management problems. Gray Watson's dmalloc package is available at @@ -79,7 +85,8 @@ set of tests. ======================================================================== -Copyright (C) 2000, 2005, 2006, 2007 Free Software Foundation, Inc. +Copyright (C) 2000, 2005, 2006, 2007, 2009 Free Software Foundation, +Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or diff --git a/configure.ac b/configure.ac index d8962cc6..ba57e399 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # Configure template for GNU m4. -*-Autoconf-*- -# Copyright (C) 1991, 1992, 1993, 1994, 2000, 2001, 2002, 2004, 2005, 2006, -# 2007, 2008 Free Software Foundation, Inc. +# Copyright (C) 1991, 1992, 1993, 1994, 2000, 2001, 2002, 2004, 2005, +# 2006, 2007, 2008, 2009 Free Software Foundation, Inc. # # This file is part of GNU M4. # @@ -183,7 +183,7 @@ AC_CHECK_SIZEOF([long long int]) ## ------------------------- ## ## C headers required by M4. ## ## ------------------------- ## -AC_CHECK_HEADERS_ONCE([limits.h sys/wait.h]) +AC_CHECK_HEADERS_ONCE([limits.h]) if test $ac_cv_header_stdbool_h = yes; then INCLUDE_STDBOOL_H='#include ' @@ -209,9 +209,14 @@ AC_FUNC_STRFTIME AC_CHECK_FUNCS_ONCE([getcwd gethostname mktime uname]) AC_CHECK_FUNCS_ONCE([setenv unsetenv putenv clearenv]) + +## ------------------ ## +## Configure options. ## +## ------------------ ## + M4_LIB_GMP AM_CONDITIONAL([USE_GMP], [test "x$USE_GMP" = xyes]) - +M4_SYSCMD ## -------- ## diff --git a/doc/m4.texinfo b/doc/m4.texinfo index 7f7bb3f3..486186e9 100644 --- a/doc/m4.texinfo +++ b/doc/m4.texinfo @@ -8052,6 +8052,15 @@ Prior to executing the command, @code{m4} flushes its buffers. The default standard input, output and error of @var{shell-command} are the same as those of @code{m4}. +By default, the @var{shell-command} will be used as the argument to the +@option{-c} option of the @command{/bin/sh} shell (or the version of +@command{sh} specified by @samp{command -p getconf PATH}, if your system +supports that). If you prefer a different shell, the +@command{configure} script can be given the option +@option{--with-syscmd-shell=@var{location}} to set the location of an +alternative shell at @acronym{GNU} @code{m4} installation; the +alternative shell must still support @option{-c}. + When the @option{--safer} option (@pxref{Operation modes, , Invoking m4}) is in effect, @code{syscmd} results in an error, since otherwise an input file could execute arbitrary code. @@ -8123,6 +8132,15 @@ the same as those of @code{m4}. The error output of @var{shell-command} is not a part of the expansion: it will appear along with the error output of @code{m4}. +By default, the @var{shell-command} will be used as the argument to the +@option{-c} option of the @command{/bin/sh} shell (or the version of +@command{sh} specified by @samp{command -p getconf PATH}, if your system +supports that). If you prefer a different shell, the +@command{configure} script can be given the option +@option{--with-syscmd-shell=@var{location}} to set the location of an +alternative shell at @acronym{GNU} @code{m4} installation; the +alternative shell must still support @option{-c}. + When the @option{--safer} option (@pxref{Operation modes, , Invoking m4}) is in effect, @code{esyscmd} results in an error, since otherwise an input file could execute arbitrary code. diff --git a/ltdl/m4/m4-syscmd.m4 b/ltdl/m4/m4-syscmd.m4 new file mode 100644 index 00000000..3feddb83 --- /dev/null +++ b/ltdl/m4/m4-syscmd.m4 @@ -0,0 +1,59 @@ +# -*- Autoconf -*- +# m4-syscmd.m4 -- Allow choice of syscmd shell. +# Written by Eric Blake +# +# Copyright (C) 2009 Free Software Foundation, Inc +# +# This file is part of GNU M4. +# +# GNU M4 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GNU M4 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# serial 1 + +# M4_SYSCMD +# --------- +# Allow user to choose different shell than /bin/sh for e?syscmd. +AC_DEFUN([M4_SYSCMD], +[AC_MSG_CHECKING([[which shell to use for syscmd]]) +AC_ARG_WITH([syscmd-shell], + [AS_HELP_STRING([--with-syscmd-shell], [shell used by syscmd [/bin/sh]])], + [case $withval in + yes[)] with_syscmd_shell=no;; + esac], [with_syscmd_shell=no]) +if test "$with_syscmd_shell" = no ; then + with_syscmd_shell=/bin/sh + if test "$cross_compiling" != yes ; then +dnl Give mingw a default that is more likely to be available. + AS_IF([AS_EXECUTABLE_P([/bin/sh])], [], + [if (cmd /c) 2>/dev/null; then with_syscmd_shell=cmd; fi]) +dnl Too bad _AS_PATH_WALK is not public. + M4_save_IFS=$IFS; IFS=$PATH_SEPARATOR + for M4_dir in `if (command -p getconf PATH) 2>/dev/null ; then + command -p getconf PATH + else + echo "/bin$PATH_SEPARATOR$PATH" + fi` + do + IFS=$M4_save_IFS + test -z "$M4_dir" && continue + AS_EXECUTABLE_P(["$M4_dir/sh"]) \ + && { with_syscmd_shell=$M4_dir/sh; break; } + done + IFS=$M4_save_IFS + fi +fi +AC_MSG_RESULT([$with_syscmd_shell]) +AC_DEFINE_UNQUOTED([M4_SYSCMD_SHELL], ["$with_syscmd_shell"], + [Shell used by syscmd and esyscmd, must accept -c argument.]) +]) diff --git a/modules/gnu.c b/modules/gnu.c index e833f552..5650c727 100644 --- a/modules/gnu.c +++ b/modules/gnu.c @@ -639,9 +639,6 @@ M4BUILTIN_HANDLER (debugmode) } -/* FIXME */ -#define SYSCMD_SHELL "/bin/sh" - /* Same as the sysymd builtin from m4.c module, but expand to the output of SHELL-COMMAND. */ @@ -666,7 +663,6 @@ M4BUILTIN_HANDLER (esyscmd) int sig_status; const char *prog_args[4] = { "sh", "-c" }; const char *caller; - const char *shell = SYSCMD_SHELL; if (m4_get_safer_opt (context)) { @@ -686,13 +682,16 @@ M4BUILTIN_HANDLER (esyscmd) m4_sysval_flush (context, false); #if W32_NATIVE - shell = prog_args[0] = "cmd"; - prog_args[1] = "/c"; + if (strstr (M4_SYSCMD_SHELL, "cmd")) + { + prog_args[0] = "cmd"; + prog_args[1] = "/c"; + } #endif prog_args[2] = cmd; caller = m4_info_name (me); errno = 0; - child = create_pipe_in (caller, shell/*FIXME*/, (char **) prog_args, + child = create_pipe_in (caller, M4_SYSCMD_SHELL, (char **) prog_args, NULL, false, true, false, &fd); if (child == -1) { diff --git a/modules/m4.c b/modules/m4.c index d4a58702..394abf3d 100644 --- a/modules/m4.c +++ b/modules/m4.c @@ -409,9 +409,6 @@ M4BUILTIN_HANDLER (defn) /* This section contains macros to handle the builtins "syscmd" and "sysval". */ -/* FIXME */ -#define SYSCMD_SHELL "/bin/sh" - /* Exit code from last "syscmd" command. */ /* FIXME - we should preserve this value across freezing. See http://lists.gnu.org/archive/html/bug-m4/2006-06/msg00059.html @@ -483,7 +480,6 @@ M4BUILTIN_HANDLER (syscmd) int status; int sig_status; const char *prog_args[4] = { "sh", "-c" }; - const char *shell = SYSCMD_SHELL; if (m4_get_safer_opt (context)) { @@ -502,12 +498,15 @@ M4BUILTIN_HANDLER (syscmd) } m4_sysval_flush (context, false); #if W32_NATIVE - shell = prog_args[0] = "cmd"; - prog_args[1] = "/c"; + if (strstr (M4_SYSCMD_SHELL, "cmd")) + { + prog_args[0] = "cmd"; + prog_args[1] = "/c"; + } #endif prog_args[2] = cmd; errno = 0; - status = execute (m4_info_name (me), shell/*FIXME*/, (char **) prog_args, + status = execute (m4_info_name (me), M4_SYSCMD_SHELL, (char **) prog_args, false, false, false, false, true, false, &sig_status); if (sig_status) { -- cgit v1.2.1