m4-commit
[Top][All Lists]
Advanced

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

[SCM] GNU M4 source repository branch, branch-1.6, updated. v1.5.89a-110


From: Eric Blake
Subject: [SCM] GNU M4 source repository branch, branch-1.6, updated. v1.5.89a-110-gd976408
Date: Fri, 13 Mar 2009 13:41:26 +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=d976408022fea5e25d4bf4f2e277ee973bfa6b80

The branch, branch-1.6 has been updated
       via  d976408022fea5e25d4bf4f2e277ee973bfa6b80 (commit)
       via  8aa4bf7cc980f16a9a7e4ccb867639aaad0d6ac7 (commit)
       via  db0e100af3931a435296abc9bcbe2a345e08cfca (commit)
       via  cd717be9951aab51956e1e8ae76bcbdd7c28cd75 (commit)
       via  3f3d4f618251bfdebdc93836bd867111324320de (commit)
      from  e31b307a840d5b7fd3abd18b01595295b26fcd4f (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 d976408022fea5e25d4bf4f2e277ee973bfa6b80
Author: Eric Blake <address@hidden>
Date:   Thu Mar 12 19:25:01 2009 -0600

    Fix awk script portability.
    
    * checks/get-them: In gsub, properly escape {.  Close all files
    before exiting.
    Reported by Gary V. Vaughan.
    
    Signed-off-by: Eric Blake <address@hidden>
    (cherry picked from commit c05bae4ccb7b39543b019d612a4bdb6b7c6f0b08)

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

    Allow configuration choice in syscmd shell.
    
    * configure.ac (SYSCMD_SHELL): New test.
    * src/builtin.c (m4_syscmd, m4_esyscmd): Use it to avoid
    hard-coding the shell location.
    * 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 db0e100af3931a435296abc9bcbe2a345e08cfca
Author: Eric Blake <address@hidden>
Date:   Mon Mar 2 07:22:17 2009 -0700

    Remove cruft now that gnulib modules do the work.
    
    * configure.ac (M4_cv_func_system_consistent): Delete.
    * src/builtin.c (M4SYSVAL_EXITBITS, M4SYSVAL_TERMSIGBITS):
    Delete.
    
    Signed-off-by: Eric Blake <address@hidden>
    (cherry picked from commit b7163441589626c1e758c71d3df2b0fcfeb11008)

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

    Use gnulib pipe module instead of popen(3).
    
    * m4/gnulib-cache.m4: Import pipe and wait-process modules.
    * src/builtin.c (m4_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 3f3d4f618251bfdebdc93836bd867111324320de
Author: Eric Blake <address@hidden>
Date:   Mon Mar 2 06:53:23 2009 -0700

    Use gnulib execute module instead of system(3).
    
    * m4/gnulib-cache.m4: Import execute module.
    * src/builtin.c (m4_sysval): Move computation...
    (m4_esyscmd): ...into caller.
    (m4_syscmd): Rewrite with execute module.
    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          |   34 +++++++++++
 NEWS               |    3 +
 README             |    9 +++-
 checks/get-them    |   19 ++++---
 configure.ac       |   70 +++++++++++-----------
 doc/m4.texinfo     |   21 ++++++-
 m4/gnulib-cache.m4 |    5 +-
 src/builtin.c      |  163 +++++++++++++++++++++++++++++-----------------------
 8 files changed, 207 insertions(+), 117 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 203fb13..06832b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,37 @@
+2009-03-12  Eric Blake  <address@hidden>
+
+       Fix awk script portability.
+       * checks/get-them: In gsub, properly escape {.  Close all files
+       before exiting.
+       Reported by Gary V. Vaughan.
+
+       Allow configuration choice in syscmd shell.
+       * configure.ac (SYSCMD_SHELL): New test.
+       * src/builtin.c (m4_syscmd, m4_esyscmd): Use it to avoid
+       hard-coding the shell location.
+       * doc/m4.texinfo (Syscmd, Esyscmd): Document this.
+       * README: Document new configure option.
+       * NEWS: Likewise.
+
+2009-03-04  Eric Blake  <address@hidden>
+
+       Remove cruft now that gnulib modules do the work.
+       * configure.ac (M4_cv_func_system_consistent): Delete.
+       * src/builtin.c (M4SYSVAL_EXITBITS, M4SYSVAL_TERMSIGBITS):
+       Delete.
+
+       Use gnulib pipe module instead of popen(3).
+       * m4/gnulib-cache.m4: Import pipe and wait-process modules.
+       * src/builtin.c (m4_esyscmd): Rewrite with pipe module.
+       Resolves a failure on AIX, reported by Gary V. Vaughan.
+
+       Use gnulib execute module instead of system(3).
+       * m4/gnulib-cache.m4: Import execute module.
+       * src/builtin.c (m4_sysval): Move computation...
+       (m4_esyscmd): ...into caller.
+       (m4_syscmd): Rewrite with execute module.
+       Resolves a failure on AIX, reported by Gary V. Vaughan.
+
 2009-03-04  Eric Blake  <address@hidden>
 
        Try to tolerate spaces in directory names in testsuite.
diff --git a/NEWS b/NEWS
index 8cdd193..cd473d2 100644
--- a/NEWS
+++ b/NEWS
@@ -169,6 +169,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 548ffb9..66807c8 100644
--- a/README
+++ b/README
@@ -34,6 +34,12 @@ See file `INSTALL' for compilation and installation 
instructions.
 See file `NEWS' for a list of major changes in the current release.
 See file `THANKS' for a list of contributors.
 
+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 --enable-changeword', you get an experimental
 feature which allows for changing the syntax of what is a "word" in
 `m4'.  This feature will not be present in m4 2.0, but will be
@@ -47,7 +53,8 @@ solution, from which the problem might be uneasy to infer.
 
 ========================================================================
 
-Copyright (C) 2000, 2005, 2006, 2007 Free Software Foundation, Inc.
+Copyright (C) 2000, 2005, 2006, 2007, 2008, 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/checks/get-them b/checks/get-them
index 6e571f0..9310a9d 100755
--- a/checks/get-them
+++ b/checks/get-them
@@ -1,8 +1,8 @@
 #!/bin/sh
 # -*- AWK -*-
 # Extract all examples from the manual source.
-# Copyright (C) 1992, 2005, 2006, 2007, 2008 Free Software Foundation,
-# Inc.
+# Copyright (C) 1992, 2005, 2006, 2007, 2008, 2009 Free Software
+# Foundation, Inc.
 #
 # This file is part of GNU M4.
 #
@@ -19,7 +19,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# This script is for use with GNU awk.
+# This script was designed under GNU awk, but hopefully portable to
+# other implementations.
 
 FILE=${1-/dev/null}
 : ${AWK=awk}
@@ -94,8 +95,8 @@ BEGIN {
     printf("dnl @ %s:%d: Origin of test\n"\
           "dnl @ expected status: %d\n"\
           "dnl @ extra options: %s\n"\
-          "dnl @ Copyright (C) 2006, 2007, 2008 Free Software Foundation,\n"\
-          "dnl @ Inc.\n"\
+          "dnl @ Copyright (C) 2006, 2007, 2008, 2009 Free Software\n"\
+          "dnl @ Foundation, Inc.\n"\
           "dnl @ This file is free software; the Free Software Foundation\n"\
           "dnl @ gives unlimited permission to copy and/or distribute it\n"\
           "dnl @ with or without modifications, as long as this notice\n"\
@@ -122,14 +123,16 @@ BEGIN {
   else
     prefix = "";
   gsub("@@", "@", $0);
-  gsub("@{", "{", $0);
+  gsub("@[{]", "{", $0);
   gsub("@}", "}", $0);
-  gsub("@w{ }", " ", $0);
-  gsub("@tabchar{}", "\t", $0);
+  gsub("@w[{] }", " ", $0);
+  gsub("@tabchar[{]}", "\t", $0);
   printf("%s%s\n", prefix, $0) >> file;
 }
 
 END {
   printf("\n");
+  if (count > 0)
+      close(file);
 }
 ' $FILE
diff --git a/configure.ac b/configure.ac
index 59b7311..85231dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
 # Configure template for GNU M4.                       -*-Autoconf-*-
-# Copyright (C) 1991, 1993, 1994, 2004, 2005, 2006, 2007, 2008 Free
-# Software Foundation, Inc.
+# Copyright (C) 1991, 1993, 1994, 2004, 2005, 2006, 2007, 2008, 2009
+# Free Software Foundation, Inc.
 #
 # This file is part of GNU M4.
 #
@@ -32,7 +32,7 @@ AC_CONFIG_HEADERS([lib/config.h:lib/config.hin])
 AC_PROG_CC
 M4_EARLY
 
-AC_CHECK_HEADERS_ONCE([siginfo.h sys/wait.h])
+AC_CHECK_HEADERS_ONCE([siginfo.h])
 AC_CHECK_TYPES([siginfo_t], [], [],
 [[#include <signal.h>
 #if HAVE_SIGINFO_H
@@ -106,38 +106,6 @@ if test "$M4_cv_use_stackovf" = yes; then
   ]])
 fi
 
-AC_CACHE_CHECK([if system() agrees with pclose()],
-  [M4_cv_func_system_consistent],
-  [AC_RUN_IFELSE([AC_LANG_PROGRAM([
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-], [int i1, i2;
-  FILE *f;
-  i1 = system ("exit 2");
-  if (i1 == -1)
-    return 1;
-  f = popen ("exit 2", "r");
-  if (!f)
-    return 1;
-  i2 = pclose (f);
-  return i1 != i2;])],
-  [M4_cv_func_system_consistent=yes], [M4_cv_func_system_consistent=no],
-  [AC_COMPILE_IFELSE([
-/* EMX on OS/2 defines WEXITSTATUS to be (x>>8)&0xff, and uses that for
-   pclose(), but for system() it uses x&0xff instead.  Otherwise, we assume
-   your system is sane and that pclose() and system() are consistent in their
-   values.  If this heuristic is wrong for your platform, report it as a bug
-   to address@hidden  */
-#ifdef __EMX__
-choke me
-#endif
-], [M4_cv_func_system_consistent=yes], [M4_cv_func_system_consistent=no])])])
-if test "$M4_cv_func_system_consistent" = no ; then
-  AC_DEFINE([FUNC_SYSTEM_BROKEN], [1],
-    [Define to 1 if the return value of system() disagrees with pclose().])
-fi
-
 AC_CACHE_CHECK([whether an open file can be renamed],
   [M4_cv_func_rename_open_file_works],
   [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
@@ -172,6 +140,38 @@ AC_ARG_ENABLE([changeword],
     AC_MSG_RESULT([no])
   fi], [AC_MSG_RESULT([no])])
 
+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([SYSCMD_SHELL], ["$with_syscmd_shell"],
+  [Shell used by syscmd and esyscmd, must accept -c argument.])
+
 M4_WITH_DMALLOC
 
 AC_CONFIG_COMMANDS([stamp-h], [[test -z "$CONFIG_HEADERS" || date > stamp-h]])
diff --git a/doc/m4.texinfo b/doc/m4.texinfo
index c558653..269e0d2 100644
--- a/doc/m4.texinfo
+++ b/doc/m4.texinfo
@@ -5045,7 +5045,8 @@ len(/*dangling comment
 @quotation
 The macro @code{changeword} and all associated functionality is
 experimental.  It is only available if the @option{--enable-changeword}
-option was given to @code{configure}, at @acronym{GNU} @code{m4} installation
+option was given to @command{configure}, at @acronym{GNU} @code{m4}
+installation
 time.  The functionality will go away in the future, to be replaced by
 other new features that are more efficient at providing the same
 capabilities.  @emph{Do not rely on it}.  Please direct your comments
@@ -7284,6 +7285,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}.
+
 The macro @code{syscmd} is recognized only with parameters.
 @end deffn
 
@@ -7352,6 +7362,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}.
+
 The macro @code{esyscmd} is recognized only with parameters.
 @end deffn
 
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
index e235e5c..3043f85 100644
--- a/m4/gnulib-cache.m4
+++ b/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=libm4 
--source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests 
--aux-dir=build-aux --with-tests --no-libtool --macro-prefix=M4 announce-gen 
assert autobuild avltree-oset binary-io clean-temp cloexec close-stream closein 
config-h dirname error fdl-1.3 fflush filenamecat flexmember fopen fopen-safer 
freadptr freadseek fseeko gendocs getopt git-version-gen gnumakefile gnupload 
gpl-3.0 hash intprops memchr2 memmem mkstemp obstack obstack-printf-posix 
progname quote regex stdbool stdint stdlib-safer strtod strtol unlocked-io 
vasnprintf-posix verror version-etc version-etc-fsf xalloc xmemdup0 xprintf 
xvasprintf-posix
+#   gnulib-tool --import --dir=. --local-dir=local --lib=libm4 
--source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests 
--aux-dir=build-aux --with-tests --no-libtool --macro-prefix=M4 announce-gen 
assert autobuild avltree-oset binary-io clean-temp cloexec close-stream closein 
config-h dirname error execute fdl-1.3 fflush filenamecat flexmember fopen 
fopen-safer freadptr freadseek fseeko gendocs getopt git-version-gen 
gnumakefile gnupload gpl-3.0 hash intprops memchr2 memmem mkstemp obstack 
obstack-printf-posix pipe progname quote regex stdbool stdint stdlib-safer 
strtod strtol unlocked-io vasnprintf-posix verror version-etc version-etc-fsf 
wait-process xalloc xmemdup0 xprintf xvasprintf-posix
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([local])
@@ -32,6 +32,7 @@ gl_MODULES([
   config-h
   dirname
   error
+  execute
   fdl-1.3
   fflush
   filenamecat
@@ -54,6 +55,7 @@ gl_MODULES([
   mkstemp
   obstack
   obstack-printf-posix
+  pipe
   progname
   quote
   regex
@@ -67,6 +69,7 @@ gl_MODULES([
   verror
   version-etc
   version-etc-fsf
+  wait-process
   xalloc
   xmemdup0
   xprintf
diff --git a/src/builtin.c b/src/builtin.c
index 6c1673d..0062ca0 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -24,12 +24,11 @@
 
 #include "m4.h"
 
+#include "execute.h"
 #include "memchr2.h"
+#include "pipe.h"
 #include "regex.h"
-
-#if HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
+#include "wait-process.h"
 
 /* Initialization of builtin and predefined macros.  The table
    "builtin_tab" is both used for initialization, and by the "builtin"
@@ -1108,35 +1107,6 @@ m4_defn (struct obstack *obs, int argc, macro_arguments 
*argv)
 | and "sysval".  "esyscmd" is GNU specific.                              |
 `------------------------------------------------------------------------*/
 
-/* Helper macros for readability.  */
-#if UNIX || defined WEXITSTATUS
-# define M4SYSVAL_EXITBITS(status)                      \
-  (WIFEXITED (status) ? WEXITSTATUS (status) : 0)
-# define M4SYSVAL_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 M4SYSVAL_EXITBITS(status) status
-# define M4SYSVAL_TERMSIGBITS(status) 0
-#endif /* !UNIX && !defined WEXITSTATUS */
-
-/* Fallback definitions if <stdlib.h> or <sys/wait.h> are inadequate.  */
-#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
-
 /* Exit code from last "syscmd" command.  */
 static int sysval;
 
@@ -1146,6 +1116,10 @@ m4_syscmd (struct obstack *obs, int argc, 
macro_arguments *argv)
   const call_info *me = arg_info (argv);
   const char *cmd = ARG (1);
   size_t len = ARG_LEN (1);
+  int status;
+  int sig_status;
+  const char *prog_args[4] = { "sh", "-c" };
+  const char *caller;
 
   if (strlen (cmd) != len)
     m4_warn (0, me, _("argument %s truncated"),
@@ -1158,17 +1132,30 @@ m4_syscmd (struct obstack *obs, int argc, 
macro_arguments *argv)
     }
 
   debug_flush_files ();
-  sysval = system (cmd);
-#if FUNC_SYSTEM_BROKEN
-  /* OS/2 has a buggy system() that returns exit status in the lowest eight
-     bits, although pclose() and WEXITSTATUS are defined to return exit
-     status in the next eight bits.  This approach can't detect signals, but
-     at least syscmd(`ls') still works when stdout is a terminal.  An
-     alternate approach is popen/insert_file/pclose, but that makes stdout
-     a pipe, which can change how some child processes behave.  */
-  if (sysval != -1)
-    sysval <<= 8;
-#endif /* FUNC_SYSTEM_BROKEN */
+#if W32_NATIVE
+  if (strstr (SYSCMD_SHELL, "cmd"))
+    {
+      prog_args[0] = "cmd";
+      prog_args[1] = "/c";
+    }
+#endif
+  prog_args[2] = cmd;
+  caller = quotearg_style_mem (locale_quoting_style, me->name, me->name_len);
+  errno = 0;
+  status = execute (caller, SYSCMD_SHELL, (char **) prog_args, false,
+                   false, false, false, true, false, &sig_status);
+  if (sig_status)
+    {
+      assert (status == 127);
+      sysval = sig_status << 8;
+    }
+  else
+    {
+      if (status == 127 && errno)
+       m4_warn (errno, me, _("cannot run command %s"),
+                quotearg_style (locale_quoting_style, cmd));
+      sysval = status;
+    }
 }
 
 static void
@@ -1177,7 +1164,13 @@ m4_esyscmd (struct obstack *obs, int argc, 
macro_arguments *argv)
   const call_info *me = arg_info (argv);
   const char *cmd = ARG (1);
   size_t len = ARG_LEN (1);
+  pid_t child;
+  int fd;
   FILE *pin;
+  int status;
+  int sig_status;
+  const char *prog_args[4] = { "sh", "-c" };
+  const char *caller;
 
   if (strlen (cmd) != len)
     m4_warn (0, me, _("argument %s truncated"),
@@ -1190,47 +1183,75 @@ m4_esyscmd (struct obstack *obs, int argc, 
macro_arguments *argv)
     }
 
   debug_flush_files ();
+#if W32_NATIVE
+  if (strstr (SYSCMD_SHELL, "cmd"))
+    {
+      prog_args[0] = "cmd";
+      prog_args[1] = "/c";
+    }
+#endif
+  prog_args[2] = cmd;
+  caller = quotearg_style_mem (locale_quoting_style, me->name, me->name_len);
   errno = 0;
-  pin = popen (cmd, "r");
-  if (pin == NULL)
+  child = create_pipe_in (caller, SYSCMD_SHELL, (char **) prog_args,
+                         NULL, false, true, false, &fd);
+  if (child == -1)
     {
-      m4_warn (errno, me, _("cannot open pipe to command %s"),
+      m4_warn (errno, me, _("cannot run command %s"),
               quotearg_style (locale_quoting_style, cmd));
-      sysval = -1;
+      sysval = 127;
+      return;
     }
-  else
+  pin = fdopen (fd, "r");
+  if (!pin)
     {
-      while (1)
+      m4_warn (errno, me, _("cannot run command %s"),
+              quotearg_style (locale_quoting_style, cmd));
+      sysval = 127;
+      close (fd);
+      return;
+    }
+  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);
+       }
+      else
+       {
+         size_t len = fread (obstack_next_free (obs), 1, avail, pin);
+         if (len <= 0)
+           break;
+         obstack_blank_fast (obs, len);
        }
-      if (ferror (pin))
-       m4_warn (errno, me, _("cannot read pipe to command %s"),
+    }
+  if (ferror (pin) || fclose (pin))
+    m4_error (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);
+      sysval = sig_status << 8;
+    }
+  else
+    {
+      if (status == 127 && errno)
+       m4_warn (errno, me, _("cannot run command %s"),
                 quotearg_style (locale_quoting_style, cmd));
-      sysval = pclose (pin);
+      sysval = status;
     }
 }
 
 static void
 m4_sysval (struct obstack *obs, int argc, macro_arguments *argv)
 {
-  shipout_int (obs, (sysval == -1 ? 127
-                    : (M4SYSVAL_EXITBITS (sysval)
-                       | M4SYSVAL_TERMSIGBITS (sysval))));
+  shipout_int (obs, sysval);
 }
 
 /*-------------------------------------------------------------------------.


hooks/post-receive
--
GNU M4 source repository




reply via email to

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