autoconf-patches
[Top][All Lists]
Advanced

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

fewer forks during shell detection


From: Eric Blake
Subject: fewer forks during shell detection
Date: Tue, 28 Oct 2008 21:53:54 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080914 Thunderbird/2.0.0.17 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm applying the following patch, which reduces the number of forks needed
during the better shell search portion of M4sh scripts.

Meanwhile, are there any shells where a message escapes when attempting to
redirect stderr of a program that can't be executed?  More to the point,
is this silent:

echo 'echo hi' > foo
chmod a-x foo
echo '...' | ./foo 2>/dev/null

or must we use (./foo) in order to squelch messages from some shell in the
 case where ./foo is not executable or not a valid binary image?  I'm
asking because _AS_RUN is currently using the subshell, after already
verifying that 'test -f shell' passes (but doesn't do 'test -x shell'),
and I'd like to remove the subshell if it is safe.

Also, we have a regression in _AS_LINENO_PREPARE.  The recent change to
put the shell detection code into the shell variables
as_suggested/as_required means hat we are now passing uses of $LINENO
through eval in order to check whether $LINENO works.  The manual warns
that this is not portable, and to prove it:

$ cat > foo <<\EOF
echo $LINENO
echo $LINENO
f="echo \$LINENO
echo \$LINENO"
eval "$f"
EOF
$ bash ./foo
1
2
5
6
$ pdksh ./foo
1
2
0
0

In other words, we are now claiming that pdksh lacks $LINENO support, even
though it does indeed support it in all the cases where the manual claims
it is portable.  Any ideas on how to rewrite the test to avoid this false
negative?

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkH3lIACgkQ84KuGfSFAYAoEACgwAUebPlCSYt41hk6uJg2F9hX
agwAniTt8/gMvIUSPp02yM065h1sr5Te
=6dTS
-----END PGP SIGNATURE-----
>From 63ec266226a0ceb591bd84bc1cef152cdb20a513 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Tue, 28 Oct 2008 21:31:12 -0600
Subject: [PATCH] Reduce forks while searching for better shell.

* lib/m4sugar/m4sh.m4 (_AS_DETECT_REQUIRED)
(_AS_DETECT_SUGGESTED): No need to provide extra subshell; _AS_RUN
already does the job.
(_AS_DETECT_BETTER_SHELL): Simplify AS_EXIT when not run in a trap
0 context.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog           |    7 +++++++
 lib/m4sugar/m4sh.m4 |   18 +++++++++---------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3d9d6fd..c1272a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2008-10-28  Eric Blake  <address@hidden>
 
+       Reduce forks while searching for better shell.
+       * lib/m4sugar/m4sh.m4 (_AS_DETECT_REQUIRED)
+       (_AS_DETECT_SUGGESTED): No need to provide extra subshell; _AS_RUN
+       already does the job.
+       (_AS_DETECT_BETTER_SHELL): Simplify AS_EXIT when not run in a trap
+       0 context.
+
        Undo needless efforts to protect $2 in $2_t.
        * lib/autoconf/types.m4 (_AC_TYPE_INT_BODY)
        (_AC_TYPE_UNSIGNED_INT_BODY): Reduce extra quoting.
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 7ba1adf..9463c61 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -158,9 +158,7 @@ $1], [^], address@hidden:@ ])])])
 # Refuse to execute under a shell that does not pass the given TEST.
 # Does not do AS_REQUIRE for the better-shell detection code.
 m4_defun([_AS_DETECT_REQUIRED],
-[m4_set_add([_AS_DETECT_REQUIRED_BODY],
-          [($1) || AS_EXIT(1)
-])])
+[m4_set_add([_AS_DETECT_REQUIRED_BODY], [$1 || AS_EXIT])])
 
 
 # _AS_DETECT_SUGGESTED(TEST)
@@ -168,9 +166,7 @@ m4_defun([_AS_DETECT_REQUIRED],
 # Prefer to execute under a shell that passes the given TEST.
 # Does not do AS_REQUIRE for the better-shell detection code.
 m4_defun([_AS_DETECT_SUGGESTED],
-[m4_set_add([_AS_DETECT_SUGGESTED_BODY],
-          [($1) || AS_EXIT(1)
-])])
+[m4_set_add([_AS_DETECT_SUGGESTED_BODY], [$1 || AS_EXIT])])
 
 
 # _AS_DETECT_SUGGESTED_PRUNE(TEST)
@@ -195,13 +191,17 @@ m4_define([_AS_DETECT_SUGGESTED_PRUNE],
 # FIXME: The code should test for the OSF bug described in
 # <http://lists.gnu.org/archive/html/autoconf-patches/2006-03/msg00081.html>.
 #
+# This code is run outside any trap 0 context, hence we can simplify AS_EXIT.
 m4_defun([_AS_DETECT_BETTER_SHELL],
 dnl Remove any tests from suggested that are also required
 [m4_set_map([_AS_DETECT_SUGGESTED_BODY], [_AS_DETECT_SUGGESTED_PRUNE])]dnl
+[m4_pushdef([AS_EXIT], [exit m4_default([$1], 1)])]dnl
 [if test "x$CONFIG_SHELL" = x; then
   as_bourne_compatible="AS_ESCAPE(m4_expand([_AS_BOURNE_COMPATIBLE]))"
-  
as_required="AS_ESCAPE(m4_expand(m4_set_contents([_AS_DETECT_REQUIRED_BODY])))"
-  
as_suggested="AS_ESCAPE(m4_expand(m4_set_contents([_AS_DETECT_SUGGESTED_BODY])))"
+  as_required="AS_ESCAPE(m4_expand(m4_set_contents([_AS_DETECT_REQUIRED_BODY],
+    m4_newline)))"
+  
as_suggested="AS_ESCAPE(m4_expand(m4_set_contents([_AS_DETECT_SUGGESTED_BODY],
+    m4_newline)))"
   AS_IF([_AS_RUN(["$as_required"])],
        [as_have_required=yes],
        [as_have_required=no])
@@ -243,7 +243,7 @@ dnl Remove any tests from suggested that are also required
       echo shell if you do have one.
       AS_EXIT(1)])])
 fi
-])# _AS_DETECT_BETTER_SHELL
+_m4_popdef([AS_EXIT])])# _AS_DETECT_BETTER_SHELL
 
 
 # _AS_PREPARE
-- 
1.6.0.2


reply via email to

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