bug-coreutils
[Top][All Lists]
Advanced

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

bug#5995: [PATCH] Fix exit status of signal handlers in shell scripts


From: Jim Meyering
Subject: bug#5995: [PATCH] Fix exit status of signal handlers in shell scripts
Date: Fri, 23 Apr 2010 16:22:36 +0200

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)/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; \
>>
>> 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 <address@hidden>
> 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.







reply via email to

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