hush: initial trap support
Denys Vlasenko
vda.linux at googlemail.com
Sun Mar 29 19:53:16 UTC 2009
2009/3/29 Mike Frysinger <vapier at gentoo.org>:
> On Sunday 29 March 2009 11:24:10 Denys Vlasenko wrote:
>> (a) I prefer all data to go to struct globals, never to .data.
>> (b) It would be nice to allocate it on first use, it's big
>> (so that scripts which never use traps don't waste memory for it).
>> (c) int sig; const char *name; is wasting 8 bytes,
>> uint8_t sig; char name[7]; is more compact.
>> (d) libbb has get_signum(str) which already does signal name or number ->
>> signal number conversion. get_signame(num) is an opposite convertor.
>> Use them, this allows you to not duplicate signal names.
>
> using the common sig funcs to do translation allows for quite a bit of
> reduction. delaying the alloc also saves on bloat. i was hoping there was a
> way we could unify the code so that hush wouldnt have to save/restore the
> sigaction at all though.
This is possible, but is it worth the trouble? struct sigaction is not
THAT big. Let's make it work correctly first.
> it'd know which ones hush wants to handle (like for
> CTRL+Z and CTRL+C) ... that may save on allocated data, but not really code,
> so maybe it isnt worth the hassle.
>
> updated patch attached
+ max_sig = get_sig_array_size();
+ if (!G.traps)
+ G.traps = xzalloc(sizeof(*G.traps) * max_sig);
You need to use NSIG here, because
+size_t FAST_FUNC get_sig_array_size(void)
+{
+ return ARRAY_SIZE(signals);
+}
returns the size of "known signal names" table,
but we need to have table as big as all *possible* signals.
NSIG is usually 65, meaning that there exist signals 1..64
>> Add a comment somewhere that we improperly execute traps at once
>> (even within, say, malloc() calls... which is rather bad)
>> while we need to wait for latest command completion.
>
> i dont follow you here ... no idea what you're talking about actually :)
bash:
# echo $$; trap "echo USR1" USR1; sleep 10
9891
< I run kill -USR1 9891 in other xterm >
USR1 < appears only after 10 seconds >
#
IOW, traps are not executed *immediately* when signal is received.
They happen after last command has terminated (or was ^Z-ed).
--
vda
More information about the busybox
mailing list