'trap' compliency?
Cristian Ionescu-Idbohrn
cristian.ionescu-idbohrn at axis.com
Sat Sep 26 15:49:46 UTC 2009
On Thu, 24 Sep 2009, Denys Vlasenko wrote:
> I see. It's an EXIT trap firing when `trap` terminates...
>
> It's not easy to fix due to some peculiarities of ash.c code.
>
> Simplest but dirty solution would be to to unset EXIT trap
> in `trap`, but it will not show EXIT in `trap` output too.
> Which is bad, but "less bad" that what we have now.
I see you found a less dirty solution :) Super, as what I'm chasing is
exactly EXIT traps.
I also see you mimic bash exactly, WRT output from $(trap). I can't
really understand why bash is doing that unuseful thing as adding the SIG
in front of the signal name. As I previously wrote:
On Wed, 23 Sep 2009, Cristian Ionescu-Idbohrn wrote:
>
> http://www.opengroup.org/onlinepubs/009695399/utilities/trap.html
> says:
>
> "The condition can be EXIT, 0 (equivalent to EXIT), or a signal specified
> using a symbolic name, without the SIG prefix"
>
> You've chosen to add the "SIG" in front of all the signal names. May I
> ask why?
>
> bash's choice is to do something more inconsistent, IMO:
>
> trap -- 'echo Ho' EXIT
> trap -- 'echo Ho' SIGINT
> trap -- 'echo Ho' SIGTERM
>
> no "SIG" in front of EXIT.
> Thing is, if the quoted piece above is to be followed when doing:
>
> eval "$save_traps"
>
> then $(trap) should output:
>
> trap -- 'echo Ho' EXIT
> trap -- 'echo Ho' INT
> trap -- 'echo Ho' TERM
>
> Does that seem reasonable?
Yes, it does :) Just skip the SIG thing. bash does that itself if you
ask it to be POSIXLY_CORRECT.
,----
| If bash is invoked with the name sh, it tries to mimic the startup
| behavior of historical versions of sh as closely as possible, while
| conforming to the POSIX standard as well.
`----
Try something like this in the test scripts:
set -o | egrep -q -w posix && set -o posix
and you'll see there's no SIG in the outout from $(trap). And something
like this:
--- ash.c.orig 2009-09-26 17:43:45.000000000 +0200
+++ ash.c 2009-09-26 17:46:04.000000000 +0200
@@ -12267,9 +12267,8 @@ trapcmd(int argc UNUSED_PARAM, char **ar
for (signo = 0; signo < NSIG; signo++) {
char *tr = trap_ptr[signo];
if (tr) {
- out1fmt("trap -- %s %s%s\n",
+ out1fmt("trap -- %s %s\n",
single_quote(tr),
- (signo == 0 ? "" : "SIG"),
get_signame(signo));
/* trap_ptr != trap only if we are in special-cased `trap` code.
* In this case, we will exit very soon, no need to free(). */
will save some bytes too :)
Cheers,
--
Cristian
More information about the busybox
mailing list