[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] Don't exit with zero in the trap handler
From: |
Blue Swirl |
Subject: |
Re: [Qemu-devel] [PATCH] Don't exit with zero in the trap handler |
Date: |
Sat, 25 Sep 2010 09:01:58 +0000 |
On Sat, Sep 25, 2010 at 8:31 AM, Loïc Minier <address@hidden> wrote:
> On Sat, Sep 25, 2010, Markus Armbruster wrote:
>> This suggests the old code screws up the exit code. It doesn't for me.
>> Unless it does at least on some platforms, it's a cleanup, not a fix,
>> and the commit message should reflect that.
>
> It does screw up the exit code for me; it seems it's because dash is
> used as /bin/sh. If I call this shell snippet:
> trap "echo trap; exit" 0 1 2 3 9 11 13 15
> exit 2
> with dash, e.g. "dash foo.sh; echo $?", I get 0, and with bash I get 2.
>
> I'm not sure what POSIX says, but given that calling exit in a trap
> handler isn't needed here, I recommend including this as a bug fix.
http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_21
"When exit is executed in a trap action, the last command is
considered to be the command that executed immediately preceding the
trap action."
It looks like dash and ksh are not compliant and use the return value
of echo or rm inside trap handler:
dash -c 'trap "sh -c \"exit 4\"; exit" 0 1 2 3 9 11 13 15;exit 3'; echo $?
4
ksh -c 'trap "sh -c \"exit 4\"; exit" 0 1 2 3 9 11 13 15;exit 3'; echo $?
4
bash -c 'trap "sh -c \"exit 4\"; exit" 0 1 2 3 9 11 13 15;exit 3'; echo $?
3
- [Qemu-devel] [PATCH] Don't exit with zero in the trap handler, Loïc Minier, 2010/09/24
- Re: [Qemu-devel] [PATCH] Don't exit with zero in the trap handler, Markus Armbruster, 2010/09/25
- Re: [Qemu-devel] [PATCH] Don't exit with zero in the trap handler, Loïc Minier, 2010/09/25
- Re: [Qemu-devel] [PATCH] Don't exit with zero in the trap handler,
Blue Swirl <=
- Re: [Qemu-devel] [PATCH] Don't exit with zero in the trap handler, Loïc Minier, 2010/09/25
- Re: [Qemu-devel] [PATCH] Don't exit with zero in the trap handler, Markus Armbruster, 2010/09/25
- Re: [Qemu-devel] [PATCH] Don't exit with zero in the trap handler, Blue Swirl, 2010/09/25
- [Qemu-devel] [PATCH] Avoid exit in trap as it breaks with some shells, Loïc Minier, 2010/09/25
- Re: [Qemu-devel] [PATCH] Avoid exit in trap as it breaks with some shells, Blue Swirl, 2010/09/26