From: Jilles Tjoelker <jilles@stack.nl>
To: Dan Muresan <danmbox@gmail.com>
Cc: dash@vger.kernel.org
Subject: Re: dash "set -e" breaks "trap INT"
Date: Sat, 13 Nov 2010 22:05:54 +0100 [thread overview]
Message-ID: <20101113210554.GA86425@stack.nl> (raw)
In-Reply-To: <AANLkTimrXpDb5z1d4PC3M=8hyN-Ob7sVb1ngF-JTem4g@mail.gmail.com>
On Wed, Nov 10, 2010 at 03:49:19PM +0200, Dan Muresan wrote:
> I've submitted a bug regarding trap + "set -e" on Ubuntu Launchpad
> [1], but that's probably not the best place to talk about the issue.
> I'm using dash 0.5.5.1-3ubuntu2 from Ubuntu Lucid on an x86 machine.
> With "set -e", only the first command in an INT trap handler gets
> executed -- UNLESS that first command is a call to a function that
> returns 0. Here's an example of the problem:
> --- 8-x ---
> #!/bin/sh
> set -e
>
> trap 'hnd' INT
> trap 'echo EXIT' EXIT
>
> zero() {
> return 0;
> }
>
> hnd() {
> #zero
> echo "Ignored 1"; echo "Ignored 2"
> sleep 1
> echo Back
> }
>
> for i in 3 2 1; do
> echo "$i"
> sleep 1 # || true
> done
>
> echo OUT
> --- 8-x ---
> If we uncomment either the call to zero, or the || true check, the
> entire handler gets executed. A set +e inside the handler makes no
> difference.
> My workaround at the moment is to trap both INT and EXIT (I'm not
> going to rely on the "zero" bit of magic). I suppose this workaround
> will unfortunately have to stick around for a while -- even if this
> bug gets fixed, scripts can't assume they are running on the latest
> version of dash.
> [1] https://bugs.launchpad.net/ubuntu/+source/dash/+bug/673119
I can reproduce this with v0.5.5.1 but not with v0.5.6 or master, so
apparently it has been fixed.
The exit after the INT trap has been executed also occurs in all other
shells I tried (newer dash, FreeBSD sh, mksh, true Bourne shell), except
ksh93 which does not execute the INT trap at all, only the EXIT trap.
The cause is that sleep also gets the SIGINT and terminates on it, which
can be seen by removing set -e and adding echo rc=$? after sleep.
ksh93 has a sleep builtin, but this has no effect on above. Behaviour
remains the same with /bin/sleep.
--
Jilles Tjoelker
prev parent reply other threads:[~2010-11-13 21:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-10 13:49 dash "set -e" breaks "trap INT" Dan Muresan
2010-11-13 21:05 ` Jilles Tjoelker [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101113210554.GA86425@stack.nl \
--to=jilles@stack.nl \
--cc=danmbox@gmail.com \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox