Hi.

2010/9/26, Loïc Minier <l...@dooz.org>:
> On Sat, Sep 25, 2010, Jilles Tjoelker wrote:
>> You are certainly right that POSIX requires this to be handled
>> differently, but there are various other shells that are non-compliant
>> in the same way as dash and it is easy to avoid the behaviour, so I
>> would not recommend depending on it.
>
>  I don't know why it was put there in the first place, but my first
>  reaction was to send patch to remove the use of exit in the trap
>  handler:
>     http://lists.gnu.org/archive/html/qemu-devel/2010-09/msg01803.html
-trap "rm -f $TMPC $TMPO $TMPE ; exit" EXIT INT QUIT TERM
+# NB: do not call "exit" in the trap handler; this is buggy with some shells;
+# see <addr...@hidden>
+trap "rm -f $TMPC $TMPO $TMPE" EXIT INT QUIT TERM
>  but the discussion led me to report this bug against dash

1) IMHO doing cleaning in a `trap` is bad coding style in the first
place. Here i think about, how much one allowed to do in signal
handlers in C? The `trap` for me is like *try / catch* exception
handling:

trap 'echo "unexpected error in script block xyz,
please send console messages and log files to d...@example.org"' EXIT

# critical part
script
block
xyz

trap "" EXIT
# ordinary part
....

2) So, when "fine POSIX" changes rules of `exit` inside `trap`, this
is even worse game playing style. While `dash` doesn't do much about
stepping over POSIX, this case shows, that standards are inflexible,
to say least, and `dash` went its own way here.

3) After dealing with 1), 2) and pipes, conclusion is that exit status
code is a very weak information source. For example, when program is
failing to free (e.g. TMP) resources, this *is* another problem, like
checking errno after close() in C -- somebody cares, the most don't.

Thus, like in many good scripts, I would have do_exit() with all kinds
of cleanup (console, files, logs etc.). And `trap` lines would have
`echo “unexpected error #xyz” ; catch_xyz || do_exit 1`

>  Thanks for your detailed reply!  Am I also expected to log this issue
>  somewhere for tracking?

Tracking what? After many years, I think, `dash` will remain such
features unchanged.
-- 
sed 'sed && sh + olecom = love'  <<  ''
-o--=O`C
 #oo'L O
<___=E M
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to