shell 'trap' woodoo :)

Denys Vlasenko vda.linux at googlemail.com
Sun Sep 12 14:06:20 UTC 2010


On Sun, Sep 12, 2010 at 9:42 AM, Cristian Ionescu-Idbohrn
<cristian.ionescu-idbohrn at axis.com> wrote:
> On Sat, 11 Sep 2010, Cristian Ionescu-Idbohrn wrote:
>> All shells run the trap action twice when hitting C-c with trap on INT.
>> With signals removed in the trap action, only bash behaves, according to
>> my experiments.
>
> Oh, I missed this: hitting C-c while 'sleep 5' executes will not interrupt
> the sleep (ash and hush).  Seems C-c is ignored.  Both SIGINT and SIGTERM
> are ignored.

I definitely see current ash and hush to react to ^C at once.
I also tested Rob's prebuilt busybox-i486 binary (v.1.17.2) from
http://impactlinux.com/aboriginal/downloads/binaries/extras/
Here is test runs:

# ./busybox-i486 ash z
running: z
^Cin : wrapper_func
in : wrapper_func
1. : wrapper_func: listing traps
trap -- 'wrapper_func' INT
trap -- 'wrapper_func' TERM
2. : wrapper_func: removing traps
3. : wrapper_func: listing traps again
in : other_func
ls: cannot access /foo/bar/baz: No such file or directory
out: other_func
out: wrapper_func
1. : wrapper_func: listing traps
2. : wrapper_func: removing traps
3. : wrapper_func: listing traps again
in : other_func
ls: cannot access /foo/bar/baz: No such file or directory
out: other_func
out: wrapper_func

# ./busybox-i486 hush z
hush: set: -e: invalid option
hush: set: -u: invalid option
running: z
^C
in : wrapper_func
1. : wrapper_func: listing traps
trap -- 'wrapper_func' EXIT
trap -- 'wrapper_func' INT
trap -- 'wrapper_func' TERM
2. : wrapper_func: removing traps
3. : wrapper_func: listing traps again
in : other_func
ls: cannot access /foo/bar/baz: No such file or directory
out: other_func
out: wrapper_func

# ./busybox-i486
BusyBox v1.17.2 (2010-09-05 04:58:49 CDT) multi-call binary.
...


> + trap wrapper_func EXIT TERM INT
> + echo running: /home/cii/axis/tests/trap-test3.sh
> running: /home/cii/axis/tests/trap-test3.sh
> + sleep 5
> ^C^C^C^C^C^C^C^C^C^C^C^C+ wrapper_func

I don't see this in my experiments.
What version and .config do you use?

> + echo in : wrapper_func
> in : wrapper_func
> + date +%s
> + echo 1. : wrapper_func: listing traps
> 1. : wrapper_func: listing traps
> + trap
> trap -- 'wrapper_func' EXIT
> trap -- 'wrapper_func' INT
> trap -- 'wrapper_func' TERM
> + echo 2. : wrapper_func: removing traps
> 2. : wrapper_func: removing traps
> + trap - EXIT INT TERM
> + echo 3. : wrapper_func: listing traps again
> 3. : wrapper_func: listing traps again
> + trap
> + other_func
> + echo in : other_func
> in : other_func
> + ls -al /foo/bar/baz
> ls: /foo/bar/baz: No such file or directory
> + :
> + echo out: other_func
> out: other_func
> + echo out: wrapper_func
> out: wrapper_func
> + exit 77
>
> Dash and dash behave as expected WRT reacting to C-c.

-- 
vda


More information about the busybox mailing list