On Sun, Jan 31, 2010 at 01:51:59AM +0100, Bruno Haible wrote: > Additionally, another proposed change prompted by Dmitry's patch. > > The Autoconf manual > <http://www.gnu.org/software/autoconf/manual/html_node/Shell-Functions.html> > says: > "the state of ‘$?’ is not reliable when entering a shell function. This has > the effect that using a function as the first command in a trap handler can > cause problems." > > Here's a proposed fix (need to handle the same problem in bootstrap yourself): > > > 2010-01-30 Bruno Haible <[email protected]> > > Avoid unportable use of $? at the beginning of a shell function. > * tests/init.sh (remove_tmp_): Don't deal with exit status here. > (setup_): Do it directly in the trap handler here. > > --- tests/init.sh.orig Sun Jan 31 01:46:23 2010 > +++ tests/init.sh Sun Jan 31 01:46:09 2010 > @@ -82,14 +82,12 @@ > # directory and exit with the incoming value of $?. > remove_tmp_() > { > - __st=$? > cleanup_ > # cd out of the directory we're about to remove > cd "$initial_cwd_" || cd / || cd /tmp > chmod -R u+rwx "$test_dir_" > # If removal fails and exit status was to be 0, then change it to 1. > rm -rf "$test_dir_" || { test $__st = 0 && __st=1; } > - exit $__st
This would break the "If removal fails" statement.
Let's pass exit code to this function as an argument:
remove_tmp_()
{
__st=$1
[...]
trap 'remove_tmp_ $?' 0
--
ldv
pgpLmt5BoBK4g.pgp
Description: PGP signature
