* about coding style (Re: exit-ing in a trap handler uses the wrong exit code)
@ 2010-09-26 0:03 Oleg Verych
2010-09-26 16:07 ` Loïc Minier
0 siblings, 1 reply; 2+ messages in thread
From: Oleg Verych @ 2010-09-26 0:03 UTC (permalink / raw)
To: Loïc Minier; +Cc: Jilles Tjoelker, dash
Hi.
2010/9/26, Loïc Minier <lool@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 <address@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 devs@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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: about coding style (Re: exit-ing in a trap handler uses the wrong exit code)
2010-09-26 0:03 about coding style (Re: exit-ing in a trap handler uses the wrong exit code) Oleg Verych
@ 2010-09-26 16:07 ` Loïc Minier
0 siblings, 0 replies; 2+ messages in thread
From: Loïc Minier @ 2010-09-26 16:07 UTC (permalink / raw)
To: Oleg Verych; +Cc: Jilles Tjoelker, dash
On Sun, Sep 26, 2010, Oleg Verych wrote:
> > 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.
Tracking bugs; certainly dash still see bug fixes, and I was hoping
that there is some kind of bug tracker to not lose reports on the
mailing-list, but I didn't find it
--
Loïc Minier
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-09-26 16:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-26 0:03 about coding style (Re: exit-ing in a trap handler uses the wrong exit code) Oleg Verych
2010-09-26 16:07 ` Loïc Minier
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.