* dash "set -e" breaks "trap INT"
@ 2010-11-10 13:49 Dan Muresan
2010-11-13 21:05 ` Jilles Tjoelker
0 siblings, 1 reply; 2+ messages in thread
From: Dan Muresan @ 2010-11-10 13:49 UTC (permalink / raw)
To: dash
Hi,
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
-- Dan
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: dash "set -e" breaks "trap INT"
2010-11-10 13:49 dash "set -e" breaks "trap INT" Dan Muresan
@ 2010-11-13 21:05 ` Jilles Tjoelker
0 siblings, 0 replies; 2+ messages in thread
From: Jilles Tjoelker @ 2010-11-13 21:05 UTC (permalink / raw)
To: Dan Muresan; +Cc: dash
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-11-13 21:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-10 13:49 dash "set -e" breaks "trap INT" Dan Muresan
2010-11-13 21:05 ` Jilles Tjoelker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox