* bug in handling of ignored traps
@ 2012-02-08 17:27 Eric Blake
2012-02-08 20:12 ` Chet Ramey
0 siblings, 1 reply; 2+ messages in thread
From: Eric Blake @ 2012-02-08 17:27 UTC (permalink / raw)
To: dash
[-- Attachment #1: Type: text/plain, Size: 1997 bytes --]
Per POSIX requirements on trap, dash is properly refusing to let
non-interactive scripts reset signal handlers via trap if the shell was
started with an inherited ignored signal handler. However, dash lies to
the user, making it impossible to tell if the user is invoking a shell
in an environment where a signal was inherited as ignored. ksh and bash
are nicer about things, and at least let the user query whether a shell
is treating a particular signal as non-resettable.
This is important for shell scripts that WANT to guarantee a particular
behavior of SIGPIPE handling (such as this thread on writing a grep test
for covering the behavior of grep both with and without SIGPIPE
inherited as ignored:
https://lists.gnu.org/archive/html/bug-grep/2012-02/msg00016.html).
Bash behavior - you can learn about the ignored handler from the get-go:
$ (trap '' PIPE; bash -c 'trap; echo 0; trap "echo 1" PIPE; trap; \
echo 2; kill -s PIPE $$; trap; echo 3')
trap -- '' SIGPIPE
0
trap -- '' SIGPIPE
2
trap -- '' SIGPIPE
3
Ksh behavior - you can learn about the ignored handler, but only after
trying to use something else:
$ (trap '' PIPE; ksh -c 'trap; echo 0; trap "echo 1" PIPE; trap; \
echo 2; kill -s PIPE $$; trap; echo 3')
0
trap -- '' PIPE
2
trap -- '' PIPE
3
dash behavior - the trap is properly ignored, but you can't learn about
it (that is, trap lies and tells you that the handler was changed):
$ (trap '' PIPE; dash -c 'trap; echo 0; trap "echo 1" PIPE; trap; \
echo 2; kill -s PIPE $$; trap; echo 3')
0
trap -- 'echo 1' PIPE
2
trap -- 'echo 1' PIPE
3
and proof that when the inheritance issue is not in play, the handler works:
$ (trap - PIPE; dash -c 'trap; echo 0; trap "echo 1" PIPE; trap; \
echo 2; kill -s PIPE $$; trap; echo 3')
0
trap -- 'echo 1' PIPE
2
1
trap -- 'echo 1' PIPE
3
--
Eric Blake eblake@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: bug in handling of ignored traps
2012-02-08 17:27 bug in handling of ignored traps Eric Blake
@ 2012-02-08 20:12 ` Chet Ramey
0 siblings, 0 replies; 2+ messages in thread
From: Chet Ramey @ 2012-02-08 20:12 UTC (permalink / raw)
To: eblake; +Cc: dash, chet
> Per POSIX requirements on trap, dash is properly refusing to let
> non-interactive scripts reset signal handlers via trap if the shell was
> started with an inherited ignored signal handler. However, dash lies to
> the user, making it impossible to tell if the user is invoking a shell
> in an environment where a signal was inherited as ignored. ksh and bash
> are nicer about things, and at least let the user query whether a shell
> is treating a particular signal as non-resettable.
I don't think this is a bug. It's more of a quality-of-implementation
issue. dash appears to be following the "no error need be reported
when attempting to do so" part of the Posix spec, which is fine. Bash
did more or less the same thing until bash-4.2.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-02-08 20:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-08 17:27 bug in handling of ignored traps Eric Blake
2012-02-08 20:12 ` Chet Ramey
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.