bug-gnulib
[Top][All Lists]
Advanced

[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:41:33 +0100
User-agent: KMail/1.9.9

Hi Jim,

> I'll propose patches for gnulib-tool and most of the tests, and leave
> bootstrap, tests/test-vc-list-files*.sh, tests/test-update-copyright.sh
> to Jim.

Here's a proposed patch for some of these:


2010-01-30  Bruno Haible  <address@hidden>

        Don't use $? in a trap handler for a signal.
        * tests/init.sh (setup_): In the trap handler, exit with code 77.
        Reported by Dmitry V. Levin <address@hidden>.

        Preserve the exit status at exit.
        * tests/test-parse-duration.sh: In the trap handler, exit with the
        intended exit status.

        Preserve the exit status at exit. Don't continue after a fatal signal.
        * tests/test-update-copyright.sh: In the exit trap handler, exit with
        the intended exit status. In the signal trap handler, exit with
        code 77.

--- tests/init.sh.orig  Sun Jan 31 01:29:01 2010
+++ tests/init.sh       Sun Jan 31 01:28:53 2010
@@ -128,7 +128,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 'Exit $?' 1 2 13 15
+  trap 'echo "Skipping test: caught fatal signal"; Exit 77' 1 2 13 15
 }
 
 # Create a temporary directory, much like mktemp -d does.
--- tests/test-parse-duration.sh.orig   Sun Jan 31 01:29:01 2010
+++ tests/test-parse-duration.sh        Sun Jan 31 01:23:47 2010
@@ -46,7 +46,7 @@
 }
 
 func_tmpdir
-trap 'rm -rf "${tmp}"' EXIT
+trap 'status=$?; rm -rf "${tmp}"; exit $status' EXIT
 tmpf="${tmp}/tests.txt"
 
 cat > "${tmpf}" <<- _EOF_
--- tests/test-update-copyright.sh.orig Sun Jan 31 01:29:01 2010
+++ tests/test-update-copyright.sh      Sun Jan 31 01:25:05 2010
@@ -24,7 +24,8 @@
 fi
 
 TMP_BASE=update-copyright.test
-trap 'rm -f $TMP_BASE*' 0 1 2 3 15
+trap 'status=$?; rm -f $TMP_BASE*; exit $status' 0
+trap 'rm -f $TMP_BASE*; (exit 77); exit 77' 1 2 3 15
 
 ## --------------------------------- ##
 ## Skip if user does not have perl.  ##




reply via email to

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