bug-coreutils
[Top][All Lists]
Advanced

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

[PATCH] Fix exit status of signal handlers in shell scripts


From: Dmitry V. Levin
Subject: [PATCH] Fix exit status of signal handlers in shell scripts
Date: Sat, 30 Jan 2010 22:18:12 +0300

The value of `$?' on entrance to signal handlers in shell scripts
cannot be relied upon, so set the exit code explicitly to
128 + SIGTERM == 143.
* src/Makefile.am (sc_tight_scope): Use `exit 143' in signal handler.
* cfg.mk (sc_always_defined_macros, sc_system_h_headers): Likewise.
* tests/test-lib.sh: Use `Exit 143' in signal handler.
---
See also
http://lists.gnu.org/archive/html/bug-gnulib/2010-01/msg00361.html

 cfg.mk            |    6 ++++--
 src/Makefile.am   |    3 ++-
 tests/test-lib.sh |    2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index b5a21c3..52e78ae 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -130,7 +130,8 @@ headers_with_interesting_macro_defs = \
 # Don't define macros that we already get from gnulib header files.
 sc_always_defined_macros: .re-defmac
        @if test -f $(srcdir)/src/system.h; then                        \
-         trap 'rc=$$?; rm -f .re-defmac; exit $$rc' 0 1 2 3 15;        \
+         trap 'rc=$$?; rm -f .re-defmac; exit $$rc' 0;                 \
+         trap 'exit 143' 1 2 3 15;                                     \
          grep -f .re-defmac $$($(VC_LIST))                             \
            && { echo '$(ME): define the above via some gnulib .h file' \
                  1>&2;  exit 1; } || :;                                \
@@ -149,7 +150,8 @@ sc_always_defined_macros: .re-defmac
 # the headers already included via system.h.
 sc_system_h_headers: .re-list
        @if test -f $(srcdir)/src/system.h; then                        \
-         trap 'rc=$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15;          \
+         trap 'rc=$$?; rm -f .re-list; exit $$rc' 0;                   \
+         trap 'exit 143' 1 2 3 15;                                     \
          grep -nE -f .re-list                                          \
              $$($(VC_LIST_EXCEPT) | grep '^src/')                      \
            && { echo '$(ME): the above are already included via system.h'\
diff --git a/src/Makefile.am b/src/Makefile.am
index c73f7dc..90e3b3e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -709,7 +709,8 @@ sc_check-AUTHORS: $(all_programs)
 .PHONY: sc_tight_scope
 sc_tight_scope: $(bin_PROGRAMS)
        $(AM_V_GEN)t=exceptions-$$$$;                                   \
-       trap "s=$$?; rm -f $$t; exit $$s" 0 1 2 13 15;                  \
+       trap "s=$$?; rm -f $$t; exit $$s" 0;                            \
+       trap "exit 143" 1 2 13 15;                                      \
        src=`for f in $(SOURCES); do                                    \
               test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;   \
        hdr=`for f in $(noinst_HEADERS); do                             \
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
index 7ad4331..81950e2 100644
--- a/tests/test-lib.sh
+++ b/tests/test-lib.sh
@@ -408,7 +408,7 @@ remove_tmp_()
 # Run each test from within a temporary sub-directory named after the
 # test itself, and arrange to remove it upon exception or normal exit.
 trap remove_tmp_ 0
-trap 'Exit $?' 1 2 13 15
+trap 'Exit 143' 1 2 13 15
 
 cd "$t_" || error_ "failed to cd to $t_"
 
-- 
ldv




reply via email to

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