diff options
author | Eric Blake <ebb9@byu.net> | 2009-03-02 06:53:23 -0700 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2009-03-13 06:14:58 -0600 |
commit | dda0922ce08566dc37d4521495f78a0fbc9bc5f7 (patch) | |
tree | 355504eb1876586fe4c37b51949857d3d635559a | |
parent | 15d8d148b77d5b94a1999a7223fc718f374a1b04 (diff) | |
download | m4-dda0922ce08566dc37d4521495f78a0fbc9bc5f7.tar.gz |
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 <ebb9@byu.net>
(cherry picked from commit 5d2f4a97b5e56a9bd0ce543c3f74ce3084808fe6)
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | ltdl/m4/gnulib-cache.m4 | 3 | ||||
-rw-r--r-- | m4/m4module.h | 1 | ||||
-rw-r--r-- | m4/utility.c | 10 | ||||
-rw-r--r-- | modules/gnu.c | 41 | ||||
-rw-r--r-- | modules/m4.c | 70 |
6 files changed, 93 insertions, 45 deletions
@@ -1,3 +1,16 @@ +2009-03-13 Eric Blake <ebb9@byu.net> + + 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 <ebb9@byu.net> Improve web-manual maintainer rule. diff --git a/ltdl/m4/gnulib-cache.m4 b/ltdl/m4/gnulib-cache.m4 index f8436dce..050fff45 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 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 # 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 diff --git a/m4/m4module.h b/m4/m4module.h index a16ca4f4..0cad1e49 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 215fabd3..c103520b 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 53a3ecb8..122e9669 100644 --- a/modules/gnu.c +++ b/modules/gnu.c @@ -28,6 +28,8 @@ # include "m4private.h" #endif +#include <sys/wait.h> + #include "modules/m4.h" #include "quotearg.h" @@ -637,6 +639,36 @@ M4BUILTIN_HANDLER (debugmode) } +/* 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 + /* Same as the sysymd builtin from m4.c module, but expand to the output of SHELL-COMMAND. */ @@ -678,9 +710,9 @@ M4BUILTIN_HANDLER (esyscmd) if (pin == NULL) { m4_error (context, 0, errno, me, - _("cannot open pipe to command %s"), + _("cannot run command %s"), quotearg_style (locale_quoting_style, cmd)); - m4_set_sysval (-1); + m4_set_sysval (127); } else { @@ -705,7 +737,10 @@ M4BUILTIN_HANDLER (esyscmd) 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)); + int result = pclose (pin); + m4_set_sysval (result == -1 ? 127 + : (M4_SYSVAL_EXITBITS (result) + | M4_SYSVAL_TERMSIGBITS (result))); } } else diff --git a/modules/m4.c b/modules/m4.c index 6844bf51..d4a58702 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. */ @@ -412,42 +409,15 @@ 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 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 +480,10 @@ 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" }; + const char *shell = SYSCMD_SHELL; if (m4_get_safer_opt (context)) { @@ -527,18 +501,32 @@ 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 + shell = 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, + 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); } |