automake-patches
[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: Ralf Wildenhues
Subject: Re: [PATCH] Fix exit status of signal handlers in shell scripts
Date: Sat, 6 Feb 2010 19:08:27 +0100
User-agent: Mutt/1.5.20 (2009-10-28)

Hello Dmitry,

* Dmitry V. Levin wrote on Sat, Jan 30, 2010 at 08:21:19PM CET:
> 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.
> * lib/am/check.am (am__check_pre): Use `exit 143' in signal handler.
> * lib/elisp-comp: Likewise.
> * lib/install-sh: Likewise.
> * lib/ylwrap: Likewise.
> ---
> See also
> http://lists.gnu.org/archive/html/bug-gnulib/2010-01/msg00361.html

Thank you!  I think the user does deserve to see the right exit status
depending on the type of signal which arrived, so I'm amending the patch
to do so.  Also, fixing the ylwrap script to trap 13, not 3, and adding
you to THANKS.

I'm adding this to the maint branch, for master and branch-1.11.
I'll be pushing it once testing finishes.
(The "tiny change" denotes that you haven't signed copyright papers yet.)

Cheers,
Ralf

2010-02-06  Dmitry V. Levin  <address@hidden>  (tiny change)
            Ralf Wildenhues  <address@hidden>

        Fix exit status of signal handlers in shell scripts.
        The value of `$?' on entrance to signal handlers in shell scripts
        cannot be relied upon, so set the exit code explicitly to
        128 + SIG<SIGNAL>.
        * lib/am/check.am (am__check_pre): Use `exit 143' in signal handler.
        * lib/elisp-comp: Likewise.
        * lib/install-sh: Likewise.
        * lib/ylwrap: Likewise.  Also, fix script to trap signal 13, not 3.
        * NEWS, THANKS: Update.
        Bug report, analysis, and initial patch by Dmitry V. Levin.

diff --git a/NEWS b/NEWS
index cd427fb..2284680 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,9 @@ Bugs fixed in 1.11.0a:
   - AM_PROG_GCJ uses AC_CHECK_TOOLS to look for `gcj' now, so that prefixed
     tools are preferred in a cross-compile setup.
 
+  - Several scripts as well as the parallel-tests testsuite driver now
+    exit with the right exit status upon receiving a signal.
+
 
 New in 1.11:
 
diff --git a/lib/am/check.am b/lib/am/check.am
index b1d1aad..755bf13 100644
--- a/lib/am/check.am
+++ b/lib/am/check.am
@@ -1,5 +1,5 @@
 ## automake - create Makefile.in from Makefile.am
-## Copyright (C) 2001, 2003, 2006, 2007, 2008, 2009 Free Software
+## Copyright (C) 2001, 2003, 2006, 2007, 2008, 2009, 2010 Free Software
 ## Foundation, Inc.
 
 ## This program is free software; you can redistribute it and/or modify
@@ -101,8 +101,9 @@ $(am__sh_e_setup);                                  \
 $(am__vpath_adj_setup) $(am__vpath_adj)                        \
 srcdir=$(srcdir); export srcdir;                       \
 rm -f address@hidden;                                          \
-trap 'st=$$?; rm -f '\''$(abs_builddir)/address@hidden'\''; (exit $$st); exit 
$$st' \
-  1 2 13 15;                                           \
+am__trap='rm -f '\''$(abs_builddir)/address@hidden'\''; (exit $$st); exit 
$$st'; \
+trap "st=129; $$am__trap" 1; trap "st=130; $$am__trap" 2;      \
+trap "st=141; $$am__trap" 13; trap "st=143; $$am__trap" 15; \
 am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;           \
 test "x$$am__odir" = x. || $(MKDIR_P) "$$am__odir" || exit $$?;        \
 if test -f "./$$f"; then dir=./;                       \
diff --git a/lib/elisp-comp b/lib/elisp-comp
index ce8c82c..ecc6b15 100755
--- a/lib/elisp-comp
+++ b/lib/elisp-comp
@@ -1,8 +1,8 @@
 #!/bin/sh
-# Copyright (C) 1995, 2000, 2003, 2004, 2005, 2009 Free Software
+# Copyright (C) 1995, 2000, 2003, 2004, 2005, 2009, 2010 Free Software
 # Foundation, Inc.
 
-scriptversion=2009-04-28.21; # UTC
+scriptversion=2010-02-06.18; # UTC
 
 # Franc,ois Pinard <address@hidden>, 1995.
 #
@@ -65,7 +65,11 @@ tempdir=elc.$$
 
 # Cleanup the temporary directory on exit.
 trap 'ret=$?; rm -rf "$tempdir" && exit $ret' 0
-trap '(exit $?); exit' 1 2 13 15
+do_exit='(exit $ret); exit $ret'
+trap "ret=129; $do_exit" 1
+trap "ret=130; $do_exit" 2
+trap "ret=141; $do_exit" 13
+trap "ret=143; $do_exit" 15
 
 mkdir $tempdir
 cp "$@" $tempdir
diff --git a/lib/install-sh b/lib/install-sh
index 6781b98..3f83ce9 100755
--- a/lib/install-sh
+++ b/lib/install-sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 # install - install a program, script, or datafile
 
-scriptversion=2009-04-28.21; # UTC
+scriptversion=2010-02-06.18; # UTC
 
 # This originates from X11R5 (mit/util/scripts/install.sh), which was
 # later released in X11R6 (xc/config/util/install.sh) with the
@@ -200,7 +200,11 @@ if test $# -eq 0; then
 fi
 
 if test -z "$dir_arg"; then
-  trap '(exit $?); exit' 1 2 13 15
+  do_exit='(exit $ret); exit $ret'
+  trap "ret=129; $do_exit" 1
+  trap "ret=130; $do_exit" 2
+  trap "ret=141; $do_exit" 13
+  trap "ret=143; $do_exit" 15
 
   # Set umask so as not to create temps with too-generous modes.
   # However, 'strip' requires both read and write access to temps.
diff --git a/lib/ylwrap b/lib/ylwrap
index 84d5634..92b2011 100755
--- a/lib/ylwrap
+++ b/lib/ylwrap
@@ -1,10 +1,10 @@
 #! /bin/sh
 # ylwrap - wrapper for lex/yacc invocations.
 
-scriptversion=2009-04-28.21; # UTC
+scriptversion=2010-02-06.18; # UTC
 
 # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
-# 2007, 2009 Free Software Foundation, Inc.
+# 2007, 2009, 2010 Free Software Foundation, Inc.
 #
 # Written by Tom Tromey <address@hidden>.
 #
@@ -99,7 +99,11 @@ esac
 # FIXME: add hostname here for parallel makes that run commands on
 # other machines.  But that might take us over the 14-char limit.
 dirname=ylwrap$$
-trap "cd '`pwd`'; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
+do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit 
$ret'
+trap "ret=129; $do_exit" 1
+trap "ret=130; $do_exit" 2
+trap "ret=141; $do_exit" 13
+trap "ret=143; $do_exit" 15
 mkdir $dirname || exit 1
 
 cd $dirname




reply via email to

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