From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 21 08:34:13 2010 Received: (at submit) by debbugs.gnu.org; 21 Apr 2010 12:34:13 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4Z87-0001tV-8D for submit@debbugs.gnu.org; Wed, 21 Apr 2010 08:34:11 -0400 Received: from mx10.gnu.org ([199.232.76.166]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4WiI-00009o-JY for submit@debbugs.gnu.org; Wed, 21 Apr 2010 05:59:23 -0400 Received: from lists.gnu.org ([199.232.76.165]:47968) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1O4WiG-0006kY-1X for submit@debbugs.gnu.org; Wed, 21 Apr 2010 05:59:20 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O4WiF-0006Gh-L4 for bug-coreutils@gnu.org; Wed, 21 Apr 2010 05:59:19 -0400 Received: from [140.186.70.92] (port=34203 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4Wi9-00069c-3T for bug-coreutils@gnu.org; Wed, 21 Apr 2010 05:59:18 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.0 (2010-01-18) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.0 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O4Wi5-0001l1-Ve for bug-coreutils@gnu.org; Wed, 21 Apr 2010 05:59:12 -0400 Received: from vint.altlinux.org ([194.107.17.35]:58395) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4Wi5-0001kr-PP for bug-coreutils@gnu.org; Wed, 21 Apr 2010 05:59:09 -0400 Received: from wo.int.altlinux.org (wo.int.altlinux.org [192.168.1.4]) by vint.altlinux.org (Postfix) with ESMTP id 154B13F8000A for ; Wed, 21 Apr 2010 09:59:09 +0000 (UTC) Received: by wo.int.altlinux.org (Postfix, from userid 508) id 07F013F4876D; Wed, 21 Apr 2010 13:59:08 +0400 (MSD) Date: Wed, 21 Apr 2010 13:59:08 +0400 From: "Dmitry V. Levin" To: bug-coreutils@gnu.org Subject: Re: [PATCH] Fix exit status of signal handlers in shell scripts Message-ID: <20100421095908.GB29967@wo.int.altlinux.org> Mail-Followup-To: bug-coreutils@gnu.org References: <20100130191812.GB8184@wo.int.altlinux.org> <4B648872.7000907@byu.net> <20100130205231.GA24087@wo.int.altlinux.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="IiVenqGWf+H9Y6IX" Content-Disposition: inline In-Reply-To: <20100130205231.GA24087@wo.int.altlinux.org> X-fingerprint: FE4C 93AB E19A 2E4C CB5D 3E4E 7CAB E6AC 9E35 361E X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 21 Apr 2010 08:34:09 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.3 (-----) --IiVenqGWf+H9Y6IX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jan 30, 2010 at 11:52:31PM +0300, Dmitry V. Levin wrote: > On Sat, Jan 30, 2010 at 12:28:50PM -0700, Eric Blake wrote: > > According to Dmitry V. Levin on 1/30/2010 12:18 PM: > > > The value of `$?' on entrance to signal handlers in shell scripts > > > cannot be relied upon, so set the exit code explicitly to > > > 128 + SIGTERM =3D=3D 143. > > > * src/Makefile.am (sc_tight_scope): Use `exit 143' in signal handler. > >=20 > > I'm not sure I like the direction this is headed in. Exiting with 143 > > when a trap is known to be caused by SIGTERM might be okay, but it would > > be even better to reraise the signal and make the shell also exit by > > SIGTERM (in case the caller can distinguish between exit by signal and > > normal exit by status > 128). But blindly giving status 143 for other > > signals, like SIGHUP, is just wrong. If you are going to munge trap > > handlers to account for races, then you need one trap handler per signal > > with an appropriate exit status for each. >=20 > One trap handler per signal is overkill in most cases. > I think that any non-zero exit status would be sufficient. I just want to remind you that the undefined behaviour still hasn't been fixed. Please make a decision what kind of fix seems to be more suitable. --=20 ldv --IiVenqGWf+H9Y6IX Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAkvOzGwACgkQfKvmrJ41Nh5BfQCgqUGN8wll8Yp4NT7AsbG2wRcq 0iMAoJte4ydJaFb8UkPm+9x52dtkPoHI =xX8u -----END PGP SIGNATURE----- --IiVenqGWf+H9Y6IX-- From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 21 10:04:50 2010 Received: (at submit) by debbugs.gnu.org; 21 Apr 2010 14:04:50 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4aXp-0002dL-U3 for submit@debbugs.gnu.org; Wed, 21 Apr 2010 10:04:50 -0400 Received: from mx10.gnu.org ([199.232.76.166]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4aXn-0002dG-EU for submit@debbugs.gnu.org; Wed, 21 Apr 2010 10:04:48 -0400 Received: from lists.gnu.org ([199.232.76.165]:59487) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1O4aXi-00063p-8P for submit@debbugs.gnu.org; Wed, 21 Apr 2010 10:04:42 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O4aXh-0005rZ-8F for bug-coreutils@gnu.org; Wed, 21 Apr 2010 10:04:41 -0400 Received: from [140.186.70.92] (port=60676 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4aXf-0005oc-9P for bug-coreutils@gnu.org; Wed, 21 Apr 2010 10:04:40 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.0 (2010-01-18) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.0 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O4aXd-0001gb-F3 for bug-coreutils@gnu.org; Wed, 21 Apr 2010 10:04:38 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]:59312) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4aXc-0001fG-Nv for bug-coreutils@gnu.org; Wed, 21 Apr 2010 10:04:37 -0400 Received: from smtp1-g21.free.fr (localhost [127.0.0.1]) by smtp1-g21.free.fr (Postfix) with ESMTP id 7B6689400E5 for ; Wed, 21 Apr 2010 16:04:31 +0200 (CEST) Received: from mx.meyering.net (mx.meyering.net [82.230.74.64]) by smtp1-g21.free.fr (Postfix) with ESMTP id 98208940154 for ; Wed, 21 Apr 2010 16:04:29 +0200 (CEST) Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id 22042A76; Wed, 21 Apr 2010 16:04:29 +0200 (CEST) From: Jim Meyering To: bug-coreutils@gnu.org Subject: Re: bug#5995: [PATCH] Fix exit status of signal handlers in shell scripts In-Reply-To: <20100421095908.GB29967@wo.int.altlinux.org> (Dmitry V. Levin's message of "Wed, 21 Apr 2010 13:59:08 +0400") References: <20100130191812.GB8184@wo.int.altlinux.org> <4B648872.7000907@byu.net> <20100130205231.GA24087@wo.int.altlinux.org> <20100421095908.GB29967@wo.int.altlinux.org> Date: Wed, 21 Apr 2010 16:04:29 +0200 Message-ID: <87tyr4aolu.fsf@meyering.net> Lines: 35 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Spam-Score: -5.1 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.1 (-----) Dmitry V. Levin wrote: > On Sat, Jan 30, 2010 at 11:52:31PM +0300, Dmitry V. Levin wrote: >> On Sat, Jan 30, 2010 at 12:28:50PM -0700, Eric Blake wrote: >> > According to Dmitry V. Levin on 1/30/2010 12:18 PM: >> > > 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. >> > >> > I'm not sure I like the direction this is headed in. Exiting with 143 >> > when a trap is known to be caused by SIGTERM might be okay, but it would >> > be even better to reraise the signal and make the shell also exit by >> > SIGTERM (in case the caller can distinguish between exit by signal and >> > normal exit by status > 128). But blindly giving status 143 for other >> > signals, like SIGHUP, is just wrong. If you are going to munge trap >> > handlers to account for races, then you need one trap handler per signal >> > with an appropriate exit status for each. >> >> One trap handler per signal is overkill in most cases. >> I think that any non-zero exit status would be sufficient. > > I just want to remind you that the undefined behaviour still hasn't been > fixed. Please make a decision what kind of fix seems to be more suitable. Thanks for the reminder. I'd prefer a solution like the one used in automake: http://git.savannah.gnu.org/cgit/automake.git/commit/?id=dbfabdfc6521979 +am__trap='rm -f '\''$(abs_builddir)/$@-t'\''; (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; \ since it preserves signals, rather than mapping all to one, which would inevitably produce misleading results some of the time. From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 22 08:30:25 2010 Received: (at submit) by debbugs.gnu.org; 22 Apr 2010 12:30:25 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4vY0-0006ic-GH for submit@debbugs.gnu.org; Thu, 22 Apr 2010 08:30:25 -0400 Received: from mx10.gnu.org ([199.232.76.166]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4uyG-0006Tb-Kc for submit@debbugs.gnu.org; Thu, 22 Apr 2010 07:53:29 -0400 Received: from lists.gnu.org ([199.232.76.165]:49704) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1O4uy9-0002JT-QJ for submit@debbugs.gnu.org; Thu, 22 Apr 2010 07:53:21 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O4uy8-0006d5-Mh for bug-coreutils@gnu.org; Thu, 22 Apr 2010 07:53:20 -0400 Received: from [140.186.70.92] (port=42580 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4uxz-0006cK-Oc for bug-coreutils@gnu.org; Thu, 22 Apr 2010 07:53:19 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.0 (2010-01-18) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.0 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O4uxw-0007ur-9M for bug-coreutils@gnu.org; Thu, 22 Apr 2010 07:53:11 -0400 Received: from vint.altlinux.org ([194.107.17.35]:39673) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4uxv-0007tt-P5 for bug-coreutils@gnu.org; Thu, 22 Apr 2010 07:53:08 -0400 Received: from wo.int.altlinux.org (wo.int.altlinux.org [192.168.1.4]) by vint.altlinux.org (Postfix) with ESMTP id EA57F3F8000A for ; Thu, 22 Apr 2010 11:53:03 +0000 (UTC) Received: by wo.int.altlinux.org (Postfix, from userid 508) id CFFD43F4876D; Thu, 22 Apr 2010 15:53:03 +0400 (MSD) Date: Thu, 22 Apr 2010 15:53:03 +0400 From: "Dmitry V. Levin" To: bug-coreutils@gnu.org Subject: Re: bug#5995: [PATCH] Fix exit status of signal handlers in shell scripts Message-ID: <20100422115303.GA23871@wo.int.altlinux.org> Mail-Followup-To: bug-coreutils@gnu.org References: <20100130191812.GB8184@wo.int.altlinux.org> <4B648872.7000907@byu.net> <20100130205231.GA24087@wo.int.altlinux.org> <20100421095908.GB29967@wo.int.altlinux.org> <87tyr4aolu.fsf@meyering.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="45Z9DzgjV8m4Oswq" Content-Disposition: inline In-Reply-To: <87tyr4aolu.fsf@meyering.net> X-fingerprint: FE4C 93AB E19A 2E4C CB5D 3E4E 7CAB E6AC 9E35 361E X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Spam-Score: -5.9 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Thu, 22 Apr 2010 08:30:19 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.2 (------) --45Z9DzgjV8m4Oswq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Apr 21, 2010 at 04:04:29PM +0200, Jim Meyering wrote: [...] > I'd prefer a solution like the one used in automake: >=20 > http://git.savannah.gnu.org/cgit/automake.git/commit/?id=3Ddbfabdfc6521979 >=20 > +am__trap=3D'rm -f '\''$(abs_builddir)/$@-t'\''; (exit $$st); exit $$= st'; \ > +trap "st=3D129; $$am__trap" 1; trap "st=3D130; $$am__trap" 2; \ > +trap "st=3D141; $$am__trap" 13; trap "st=3D143; $$am__trap" 15; \ >=20 > since it preserves signals, rather than mapping all to one, > which would inevitably produce misleading results some of the time. Something like this? =46rom 5c36d056cbd46c43cb0bb54175fcc06b1b6069be Mon Sep 17 00:00:00 2001 From: Dmitry V. Levin Date: Sat, 30 Jan 2010 16:02:36 +0000 Subject: [PATCH] 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. * cfg.mk (sc_always_defined_macros, sc_system_h_headers): Set the exit code in signal handler explicitly to 128 + SIG. * src/Makefile.am (sc_tight_scope): Likewise. * tests/test-lib.sh: Likewise. --- cfg.mk | 10 ++++++++-- src/Makefile.am | 5 ++++- tests/test-lib.sh | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cfg.mk b/cfg.mk index 7533930..71bcb55 100644 --- a/cfg.mk +++ b/cfg.mk @@ -134,7 +134,10 @@ headers_with_interesting_macro_defs =3D \ # 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=3D$$?; rm -f .re-defmac; exit $$rc' 0 1 2 3 15; \ + trap 'rc=3D$$?; rm -f .re-defmac; exit $$rc' 0; \ + am__exit=3D'(exit $rc); exit $rc'; \ + trap "rc=3D129; $$am__exit" 1; trap "rc=3D130; $$am__exit" 2; \ + trap "rc=3D131; $$am__exit" 3; trap "rc=3D143; $$am__exit" 15; \ grep -f .re-defmac $$($(VC_LIST)) \ && { echo '$(ME): define the above via some gnulib .h file' \ 1>&2; exit 1; } || :; \ @@ -153,7 +156,10 @@ 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=3D$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15; \ + trap 'rc=3D$$?; rm -f .re-list; exit $$rc' 0; \ + am__exit=3D'(exit $rc); exit $rc'; \ + trap "rc=3D129; $$am__exit" 1; trap "rc=3D130; $$am__exit" 2; \ + trap "rc=3D131; $$am__exit" 3; trap "rc=3D143; $$am__exit" 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 20b306d..db5359b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -721,7 +721,10 @@ sc_check-AUTHORS: $(all_programs) .PHONY: sc_tight_scope sc_tight_scope: $(bin_PROGRAMS) @t=3Dexceptions-$$$$; \ - trap "s=3D$$?; rm -f $$t; exit $$s" 0 1 2 13 15; \ + trap 's=3D$$?; rm -f $$t; exit $$s' 0; \ + am__exit=3D'(exit $s); exit $s'; \ + trap "s=3D129; $$am__exit" 1; trap "s=3D130; $$am__exit" 2; \ + trap "s=3D141; $$am__exit" 13; trap "s=3D143; $$am__exit" 15; \ src=3D`for f in $(SOURCES); do \ test -f $$f && d=3D || d=3D$(srcdir)/; echo $$d$$f; done`; \ hdr=3D`for f in $(noinst_HEADERS); do \ diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 7ad4331..8bf5601 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -408,7 +408,10 @@ 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 129' 1 +trap 'Exit 130' 2 +trap 'Exit 141' 13 +trap 'Exit 143' 15 =20 cd "$t_" || error_ "failed to cd to $t_" P.S. I wonder why cfg.mk installs a signal handler for SIGQUIT while src/Makefile.am installs a signal handler for SIGPIPE instead. =20 --=20 ldv --45Z9DzgjV8m4Oswq Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAkvQOJ8ACgkQfKvmrJ41Nh7XUgCfciqtJA3qpVX2zuLWMHPiJfIQ umkAoLI91GXfOSsRGHdbQFgvbO+xNtkz =hWXQ -----END PGP SIGNATURE----- --45Z9DzgjV8m4Oswq-- From debbugs-submit-bounces@debbugs.gnu.org Fri Apr 23 10:23:00 2010 Received: (at submit) by debbugs.gnu.org; 23 Apr 2010 14:23:00 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O5JmW-0002nA-9L for submit@debbugs.gnu.org; Fri, 23 Apr 2010 10:23:00 -0400 Received: from mail.gnu.org ([199.232.76.166] helo=mx10.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O5JmT-0002n4-JT for submit@debbugs.gnu.org; Fri, 23 Apr 2010 10:22:58 -0400 Received: from lists.gnu.org ([199.232.76.165]:41023) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1O5JmO-0005FY-6i for submit@debbugs.gnu.org; Fri, 23 Apr 2010 10:22:52 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O5JmN-0006S2-3K for bug-coreutils@gnu.org; Fri, 23 Apr 2010 10:22:51 -0400 Received: from [140.186.70.92] (port=37246 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O5JmL-0006RQ-JA for bug-coreutils@gnu.org; Fri, 23 Apr 2010 10:22:50 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.0 (2010-01-18) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.0 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O5JmF-0001SF-KP for bug-coreutils@gnu.org; Fri, 23 Apr 2010 10:22:49 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]:57879) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O5JmF-0001S3-1H for bug-coreutils@gnu.org; Fri, 23 Apr 2010 10:22:43 -0400 Received: from smtp1-g21.free.fr (localhost [127.0.0.1]) by smtp1-g21.free.fr (Postfix) with ESMTP id 9287E940169 for ; Fri, 23 Apr 2010 16:22:38 +0200 (CEST) Received: from mx.meyering.net (mx.meyering.net [82.230.74.64]) by smtp1-g21.free.fr (Postfix) with ESMTP id 77E3B94014D for ; Fri, 23 Apr 2010 16:22:36 +0200 (CEST) Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id 24216C15; Fri, 23 Apr 2010 16:22:36 +0200 (CEST) From: Jim Meyering To: bug-coreutils@gnu.org Subject: Re: bug#5995: [PATCH] Fix exit status of signal handlers in shell scripts In-Reply-To: <20100422115303.GA23871@wo.int.altlinux.org> (Dmitry V. Levin's message of "Thu, 22 Apr 2010 15:53:03 +0400") References: <20100130191812.GB8184@wo.int.altlinux.org> <4B648872.7000907@byu.net> <20100130205231.GA24087@wo.int.altlinux.org> <20100421095908.GB29967@wo.int.altlinux.org> <87tyr4aolu.fsf@meyering.net> <20100422115303.GA23871@wo.int.altlinux.org> Date: Fri, 23 Apr 2010 16:22:36 +0200 Message-ID: <87mxwu1c5v.fsf@meyering.net> Lines: 51 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Spam-Score: -5.1 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.1 (-----) Dmitry V. Levin wrote: > On Wed, Apr 21, 2010 at 04:04:29PM +0200, Jim Meyering wrote: > [...] >> I'd prefer a solution like the one used in automake: >> >> http://git.savannah.gnu.org/cgit/automake.git/commit/?id=dbfabdfc6521979 >> >> +am__trap='rm -f '\''$(abs_builddir)/$@-t'\''; (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; \ >> >> since it preserves signals, rather than mapping all to one, >> which would inevitably produce misleading results some of the time. > > Something like this? > > From 5c36d056cbd46c43cb0bb54175fcc06b1b6069be Mon Sep 17 00:00:00 2001 > From: Dmitry V. Levin > Date: Sat, 30 Jan 2010 16:02:36 +0000 > Subject: [PATCH] Fix exit status of signal handlers in shell scripts Thank you! That looks like just what I wanted. > The value of `$?' on entrance to signal handlers in shell scripts > cannot be relied upon, so set the exit code explicitly. > ... > - trap 'rc=$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15; \ ... > -trap 'Exit $?' 1 2 13 15 > +trap 'Exit 129' 1 > +trap 'Exit 130' 2 > +trap 'Exit 141' 13 > +trap 'Exit 143' 15 ... > P.S. I wonder why cfg.mk installs a signal handler for SIGQUIT while > src/Makefile.am installs a signal handler for SIGPIPE instead. Well caught. I don't recall when I first added "13" (SIGPIPE), but do see that its use dates back to 2000, where it was used in the original tests/sample-test: http://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=10d2bd9fe1475b among other test scripts. I do recall explicitly adding "3" (SIGQUIT), since that can certainly be used to interrupt a test, and we should clean up after it just like we do for other catchable signals. I'll add the "3" to test-lib.sh and the 13 to the others after coreutils-8.5. For now I've applied your patch, as-is. From debbugs-submit-bounces@debbugs.gnu.org Fri Apr 30 13:34:34 2010 Received: (at control) by debbugs.gnu.org; 30 Apr 2010 17:34:34 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O7u6j-0005NE-42 for submit@debbugs.gnu.org; Fri, 30 Apr 2010 13:34:33 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O7u6h-0005N7-UK for control@debbugs.gnu.org; Fri, 30 Apr 2010 13:34:32 -0400 Received: from smtp1-g21.free.fr (localhost [127.0.0.1]) by smtp1-g21.free.fr (Postfix) with ESMTP id BD06494014F for ; Fri, 30 Apr 2010 19:34:24 +0200 (CEST) Received: from mx.meyering.net (mx.meyering.net [82.230.74.64]) by smtp1-g21.free.fr (Postfix) with ESMTP id D6A11940096 for ; Fri, 30 Apr 2010 19:34:21 +0200 (CEST) Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id BA9D610350; Fri, 30 Apr 2010 19:34:21 +0200 (CEST) From: Jim Meyering To: control@debbugs.gnu.org Subject: control Date: Fri, 30 Apr 2010 19:34:21 +0200 Message-ID: <87vdb8kfoi.fsf@meyering.net> Lines: 4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Score: -2.1 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.1 (--) close 5995 close 5925 close 6051 tags 5962 + wishlist From unknown Sat Jun 21 05:01:14 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 29 May 2010 11:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator