m4-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU M4 source repository branch, master, updated. cvs-readonly-209


From: Eric Blake
Subject: [SCM] GNU M4 source repository branch, master, updated. cvs-readonly-209-g979fcdc
Date: Fri, 13 Mar 2009 13:41:05 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU M4 source repository".

http://git.sv.gnu.org/gitweb/?p=m4.git;a=commitdiff;h=979fcdc4cfe76c0df7e3ec6450df03a366e5f3b7

The branch, master has been updated
       via  979fcdc4cfe76c0df7e3ec6450df03a366e5f3b7 (commit)
       via  54a1ab447fc79ed0f817e6b8e140ac2fd49b6e62 (commit)
       via  dda0922ce08566dc37d4521495f78a0fbc9bc5f7 (commit)
      from  15d8d148b77d5b94a1999a7223fc718f374a1b04 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 979fcdc4cfe76c0df7e3ec6450df03a366e5f3b7
Author: Eric Blake <address@hidden>
Date:   Mon Mar 2 15:08:31 2009 -0700

    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
    <sys/wait.h>.
    * 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 <address@hidden>
    (cherry picked from commit 060b5319b3452a2464eea1defc5fae608a12b574)

commit 54a1ab447fc79ed0f817e6b8e140ac2fd49b6e62
Author: Eric Blake <address@hidden>
Date:   Mon Mar 2 06:54:28 2009 -0700

    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):
    Delete.
    (esyscmd): Rewrite with pipe module.
    Resolves a failure on AIX, reported by Gary V. Vaughan.
    
    Signed-off-by: Eric Blake <address@hidden>
    (cherry picked from commit 9915ef54d55fae837209bc87d35c777715653bed)

commit dda0922ce08566dc37d4521495f78a0fbc9bc5f7
Author: Eric Blake <address@hidden>
Date:   Mon Mar 2 06:53:23 2009 -0700

    Use gnulib execute module instead of system(3).
    
    * ltdl/m4/gnulib-cache.m4: Import execute module.
    * m4/utility.c (m4_info_name): New function.
    * m4/m4module.h (m4_info_name): New prototype.
    * modules/m4.c (syscmd): Rewrite with execute module.
    (M4_SYSVAL_EXITBITS, M4_SYSVAL_TERMSIGBITS, m4_sysval): Move
    computation...
    * modules/gnu.c (M4_SYSVAL_EXITBITS, M4_SYSVAL_TERMSIGBITS)
    (esyscmd): ...here.
    Resolves a failure on AIX, reported by Gary V. Vaughan.
    
    Signed-off-by: Eric Blake <address@hidden>
    (cherry picked from commit 5d2f4a97b5e56a9bd0ce543c3f74ce3084808fe6)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog               |   33 +++++++++++++++++
 NEWS                    |    3 ++
 README                  |    9 ++++-
 configure.ac            |   13 +++++--
 doc/m4.texinfo          |   18 +++++++++
 ltdl/m4/gnulib-cache.m4 |    5 ++-
 ltdl/m4/m4-syscmd.m4    |   59 ++++++++++++++++++++++++++++++
 m4/m4module.h           |    1 +
 m4/utility.c            |   10 +++++
 modules/gnu.c           |   90 +++++++++++++++++++++++++++++++++-------------
 modules/m4.c            |   69 ++++++++++++++---------------------
 11 files changed, 237 insertions(+), 73 deletions(-)
 create mode 100644 ltdl/m4/m4-syscmd.m4

diff --git a/ChangeLog b/ChangeLog
index 7ecc47d..30f1c16 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2009-03-13  Eric Blake  <address@hidden>
+
+       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
+       <sys/wait.h>.
+       * 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):
+       Delete.
+       (esyscmd): Rewrite with pipe module.
+       Resolves a failure on AIX, reported by Gary V. Vaughan.
+
+       Use gnulib execute module instead of system(3).
+       * ltdl/m4/gnulib-cache.m4: Import execute module.
+       * m4/utility.c (m4_info_name): New function.
+       * m4/m4module.h (m4_info_name): New prototype.
+       * modules/m4.c (syscmd): Rewrite with execute module.
+       (M4_SYSVAL_EXITBITS, M4_SYSVAL_TERMSIGBITS, m4_sysval): Move
+       computation...
+       * modules/gnu.c (M4_SYSVAL_EXITBITS, M4_SYSVAL_TERMSIGBITS)
+       (esyscmd): ...here.
+       Resolves a failure on AIX, reported by Gary V. Vaughan.
+
 2009-03-05  Eric Blake  <address@hidden>
 
        Improve web-manual maintainer rule.
diff --git a/NEWS b/NEWS
index d2d42b5..4c6a76a 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 390de38..a128a02 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 d8962cc..ba57e39 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 <stdbool.h>'
@@ -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 7f7bb3f..486186e 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
address@hidden option of the @command{/bin/sh} shell (or the version of
address@hidden specified by @samp{command -p getconf PATH}, if your system
+supports that).  If you prefer a different shell, the
address@hidden script can be given the option
address@hidden@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
address@hidden option of the @command{/bin/sh} shell (or the version of
address@hidden specified by @samp{command -p getconf PATH}, if your system
+supports that).  If you prefer a different shell, the
address@hidden script can be given the option
address@hidden@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/gnulib-cache.m4 b/ltdl/m4/gnulib-cache.m4
index f8436dc..9e664da 100644
--- a/ltdl/m4/gnulib-cache.m4
+++ b/ltdl/m4/gnulib-cache.m4
@@ -15,7 +15,7 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --local-dir=local --lib=libgnu 
--source-base=gnu --m4-base=ltdl/m4 --doc-base=doc --tests-base=tests/gnu 
--aux-dir=build-aux --with-tests --libtool --macro-prefix=M4 assert autobuild 
avltree-oset binary-io clean-temp cloexec close-stream closein config-h 
configmake dirname error exit fdl-1.3 fflush filenamecat flexmember fopen 
fopen-safer freadptr freadseek fseeko gendocs gettext git-version-gen 
gnumakefile gnupload gpl-3.0 intprops memchr2 memmem mkstemp obstack 
obstack-printf-posix progname propername quote regex regexprops-generic 
sprintf-posix stdbool stdlib-safer strnlen strtod strtol tempname unlocked-io 
vasnprintf-posix verify verror xalloc xalloc-die xmemdup0 xprintf-posix 
xstrndup xvasprintf-posix
+#   gnulib-tool --import --dir=. --local-dir=local --lib=libgnu 
--source-base=gnu --m4-base=ltdl/m4 --doc-base=doc --tests-base=tests/gnu 
--aux-dir=build-aux --with-tests --libtool --macro-prefix=M4 assert autobuild 
avltree-oset binary-io clean-temp cloexec close-stream closein config-h 
configmake dirname error execute exit fdl-1.3 fflush filenamecat flexmember 
fopen fopen-safer freadptr freadseek fseeko gendocs gettext git-version-gen 
gnumakefile gnupload gpl-3.0 intprops memchr2 memmem mkstemp obstack 
obstack-printf-posix pipe progname propername quote regex regexprops-generic 
sprintf-posix stdbool stdlib-safer strnlen strtod strtol tempname unlocked-io 
vasnprintf-posix verify verror wait-process xalloc xalloc-die xmemdup0 
xprintf-posix xstrndup xvasprintf-posix
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([local])
@@ -32,6 +32,7 @@ gl_MODULES([
   configmake
   dirname
   error
+  execute
   exit
   fdl-1.3
   fflush
@@ -54,6 +55,7 @@ gl_MODULES([
   mkstemp
   obstack
   obstack-printf-posix
+  pipe
   progname
   propername
   quote
@@ -70,6 +72,7 @@ gl_MODULES([
   vasnprintf-posix
   verify
   verror
+  wait-process
   xalloc
   xalloc-die
   xmemdup0
diff --git a/ltdl/m4/m4-syscmd.m4 b/ltdl/m4/m4-syscmd.m4
new file mode 100644
index 0000000..3feddb8
--- /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 <address@hidden>
+#
+# 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 <http://www.gnu.org/licenses/>.
+
+# 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/m4/m4module.h b/m4/m4module.h
index a16ca4f..0cad1e4 100644
--- a/m4/m4module.h
+++ b/m4/m4module.h
@@ -174,6 +174,7 @@ extern bool m4_numeric_arg     (m4 *, const m4_call_info *, 
const char *,
 extern bool    m4_parse_truth_arg (m4 *, const m4_call_info *, const char *,
                                    size_t, bool);
 extern m4_symbol *m4_symbol_value_lookup (m4 *, m4_macro_args *, size_t, bool);
+extern const char *m4_info_name           (const m4_call_info *);
 
 /* Error handling.  */
 extern void m4_error (m4 *, int, int, const m4_call_info *, const char *, ...)
diff --git a/m4/utility.c b/m4/utility.c
index 215fabd..c103520 100644
--- a/m4/utility.c
+++ b/m4/utility.c
@@ -153,6 +153,16 @@ m4_symbol_value_lookup (m4 *context, m4_macro_args *argv, 
size_t i,
   return result;
 }
 
+/* Return an escaped version of the macro name corresponding to
+   CALLER, for use in error messages that do not use the m4_warn
+   machinery.  This call occupies slot 0 of the quotearg
+   machinery.  */
+const char *m4_info_name (const m4_call_info *caller)
+{
+  return quotearg_style_mem (locale_quoting_style, caller->name,
+                            caller->name_len);
+}
+
 /* Helper for all error reporting.  Report message based on FORMAT and
    ARGS, on behalf of CALLER (if any), otherwise at the global
    position in CONTEXT.  If ERRNUM, decode the errno value as part of
diff --git a/modules/gnu.c b/modules/gnu.c
index 53a3ecb..5650c72 100644
--- a/modules/gnu.c
+++ b/modules/gnu.c
@@ -29,7 +29,9 @@
 #endif
 
 #include "modules/m4.h"
+#include "pipe.h"
 #include "quotearg.h"
+#include "wait-process.h"
 
 /* Rename exported symbols for dlpreload()ing.  */
 #define m4_builtin_table       gnu_LTX_m4_builtin_table
@@ -654,7 +656,13 @@ M4BUILTIN_HANDLER (esyscmd)
 
   if (m4_set_sysval && m4_sysval_flush)
     {
+      pid_t child;
+      int fd;
       FILE *pin;
+      int status;
+      int sig_status;
+      const char *prog_args[4] = { "sh", "-c" };
+      const char *caller;
 
       if (m4_get_safer_opt (context))
        {
@@ -673,39 +681,69 @@ M4BUILTIN_HANDLER (esyscmd)
        }
 
       m4_sysval_flush (context, false);
+#if W32_NATIVE
+      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;
-      pin = popen (cmd, "r");
-      if (pin == NULL)
+      child = create_pipe_in (caller, M4_SYSCMD_SHELL, (char **) prog_args,
+                             NULL, false, true, false, &fd);
+      if (child == -1)
+       {
+         m4_error (context, 0, errno, me, _("cannot run command %s"),
+                   quotearg_style (locale_quoting_style, cmd));
+         m4_set_sysval (127);
+         return;
+       }
+      pin = fdopen (fd, "r");
+      if (!pin)
        {
-         m4_error (context, 0, errno, me,
-                   _("cannot open pipe to command %s"),
+         m4_error (context, 0, errno, me, _("cannot run command %s"),
                    quotearg_style (locale_quoting_style, cmd));
-         m4_set_sysval (-1);
+         m4_set_sysval (127);
+         close (fd);
+         return;
        }
-      else
+      while (1)
        {
-         while (1)
+         size_t avail = obstack_room (obs);
+         if (!avail)
            {
-             size_t avail = obstack_room (obs);
-             if (!avail)
-               {
-                 int ch = getc (pin);
-                 if (ch == EOF)
-                   break;
-                 obstack_1grow (obs, ch);
-               }
-             else
-               {
-                 size_t len = fread (obstack_next_free (obs), 1, avail, pin);
-                 if (len <= 0)
-                   break;
-                 obstack_blank_fast (obs, len);
-               }
+             int ch = getc (pin);
+             if (ch == EOF)
+               break;
+             obstack_1grow (obs, ch);
            }
-         if (ferror (pin))
-           m4_warn (context, errno, me, _("cannot read pipe to command %s"),
-                    quotearg_style (locale_quoting_style, cmd));
-         m4_set_sysval (pclose (pin));
+         else
+           {
+             size_t len = fread (obstack_next_free (obs), 1, avail, pin);
+             if (len <= 0)
+               break;
+             obstack_blank_fast (obs, len);
+           }
+       }
+      if (ferror (pin) || fclose (pin))
+       m4_error (context, EXIT_FAILURE, errno, me,
+                 _("cannot read pipe to command %s"),
+                 quotearg_style (locale_quoting_style, cmd));
+      status = wait_subprocess (child, caller, false, false, true, false,
+                               &sig_status);
+      if (sig_status)
+       {
+         assert (status == 127);
+         m4_set_sysval (sig_status << 8);
+       }
+      else
+       {
+         if (status == 127 && errno)
+           m4_error (context, 0, errno, me, _("cannot run command %s"),
+                     quotearg_style (locale_quoting_style, cmd));
+         m4_set_sysval (status);
        }
     }
   else
diff --git a/modules/m4.c b/modules/m4.c
index 6844bf5..394abf3 100644
--- a/modules/m4.c
+++ b/modules/m4.c
@@ -28,16 +28,13 @@
 #  include "m4private.h"
 #endif
 
+#include "execute.h"
 #include "memchr2.h"
 #include "quotearg.h"
 #include "stdlib--.h"
 #include "tempname.h"
 #include "unistd--.h"
 
-#if HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
-
 #include <modules/m4.h>
 
 /* Rename exported symbols for dlpreload()ing.  */
@@ -418,36 +415,6 @@ M4BUILTIN_HANDLER (defn)
    for ideas on how do to that.  */
 static int  m4_sysval = 0;
 
-/* Helper macros for readability.  */
-#if UNIX || defined WEXITSTATUS
-# define M4_SYSVAL_EXITBITS(status)                    \
-   (WIFEXITED (status) ? WEXITSTATUS (status) : 0)
-# define M4_SYSVAL_TERMSIGBITS(status)                 \
-   (WIFSIGNALED (status) ? WTERMSIG (status) << 8 : 0)
-
-#else /* !UNIX && !defined WEXITSTATUS */
-/* Platforms such as mingw do not support the notion of reporting
-   which signal terminated a process.  Furthermore if WEXITSTATUS was
-   not provided, then the exit value is in the low eight bits.  */
-# define M4_SYSVAL_EXITBITS(status) status
-# define M4_SYSVAL_TERMSIGBITS(status) 0
-#endif /* !UNIX && !defined WEXITSTATUS */
-
-/* Fallback definitions if <stdlib.h> or <sys/wait.h> are inadequate.  */
-/* FIXME - this may fit better as a gnulib module.  */
-#ifndef WEXITSTATUS
-# define WEXITSTATUS(status) (((status) >> 8) & 0xff)
-#endif
-#ifndef WTERMSIG
-# define WTERMSIG(status) ((status) & 0x7f)
-#endif
-#ifndef WIFSIGNALED
-# define WIFSIGNALED(status) (WTERMSIG (status) != 0)
-#endif
-#ifndef WIFEXITED
-# define WIFEXITED(status) (WTERMSIG (status) == 0)
-#endif
-
 void
 m4_set_sysval (int value)
 {
@@ -510,6 +477,9 @@ M4BUILTIN_HANDLER (syscmd)
   const m4_call_info *me = m4_arg_info (argv);
   const char *cmd = M4ARG (1);
   size_t len = M4ARGLEN (1);
+  int status;
+  int sig_status;
+  const char *prog_args[4] = { "sh", "-c" };
 
   if (m4_get_safer_opt (context))
     {
@@ -527,18 +497,35 @@ M4BUILTIN_HANDLER (syscmd)
       return;
     }
   m4_sysval_flush (context, false);
-  m4_sysval = system (cmd);
-  /* FIXME - determine if libtool works for OS/2, in which case the
-     FUNC_SYSTEM_BROKEN section on the branch must be ported to work
-     around the bug in their EMX libc system().  */
+#if W32_NATIVE
+  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), M4_SYSCMD_SHELL, (char **) prog_args,
+                   false, false, false, false, true, false, &sig_status);
+  if (sig_status)
+    {
+      assert (status == 127);
+      m4_sysval = sig_status << 8;
+    }
+  else
+    {
+      if (status == 127 && errno)
+       m4_warn (context, errno, me, _("cannot run command %s"),
+                quotearg_style (locale_quoting_style, cmd));
+      m4_sysval = status;
+    }
 }
 
 
 M4BUILTIN_HANDLER (sysval)
 {
-  m4_shipout_int (obs, (m4_sysval == -1 ? 127
-                       : (M4_SYSVAL_EXITBITS (m4_sysval)
-                          | M4_SYSVAL_TERMSIGBITS (m4_sysval))));
+  m4_shipout_int (obs, m4_sysval);
 }
 
 


hooks/post-receive
--
GNU M4 source repository




reply via email to

[Prev in Thread] Current Thread [Next in Thread]