[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Fix exit status of signal handlers in shell scripts
From: |
Bruno Haible |
Subject: |
Re: [PATCH] Fix exit status of signal handlers in shell scripts |
Date: |
Sun, 31 Jan 2010 01:51:59 +0100 |
User-agent: |
KMail/1.9.9 |
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 <address@hidden>
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
}
# Use this function to prepend to PATH an absolute name for each
@@ -127,7 +125,7 @@
# This pair of trap statements ensures that the temporary directory,
# $test_dir_, is removed upon exit as well as upon catchable signal.
- trap remove_tmp_ 0
+ trap 'status=$?; remove_tmp_; exit $status' 0
trap 'Exit $?' 1 2 13 15
}