Bug 1969 - Ash trap command causes current running commands to return immediately
Summary: Ash trap command causes current running commands to return immediately
Status: RESOLVED WORKSFORME
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: unspecified
Hardware: Other Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-07 18:06 UTC by Jake Magee
Modified: 2010-06-21 00:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jake Magee 2010-06-07 18:06:01 UTC
OVERVIEW:
When using traps in Ash scripts, currently running commands return immediately when the trap signal is sent.

On an Ubuntu system running Bash, the trap is executed when the currently running command has completed.  This is the expected execution according to section 12.2.2 of the Bash Guide for Beginners (http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_12_02.html).

STEPS TO REPRODUCE:
The following code is an example:
#!/bin/sh

trap 'echo jake' SIGUSR1

while true
do

        echo "before sleep"
        sleep 5
        echo "after sleep"
done

ACTUAL RESULTS:
trap immediately interrupts the currently running process (echo "jake").

EXPECTED RESULTS:
trap is pending until the 5 second sleep is done.

PLATFORM:
Using BusyBox 1.11.2 on a PowerPC Linux (OpenWRT 8.01) system.
Comment 1 Denys Vlasenko 2010-06-08 03:09:02 UTC
Which bbox version is it?
How do you send USR1 to it?

I am trying to reproduce it with current git:

#!/bin/sh
trap 'echo jake' SIGUSR1
echo pid:$$
while true; do
        echo "before sleep `date +'%H:%M:%S'`"
        sleep 5
        echo "after sleep `date +'%H:%M:%S'`"
done

# ./busybox ash z
pid:11975
before sleep 05:06:04
after sleep 05:06:09
before sleep 05:06:09
after sleep 05:06:14
before sleep 05:06:14
after sleep 05:06:19
before sleep 05:06:19
after sleep 05:06:24
before sleep 05:06:24
after sleep 05:06:29
before sleep 05:06:29
jake
after sleep 05:06:34
before sleep 05:06:34
jake
after sleep 05:06:39
before sleep 05:06:39
jake
after sleep 05:06:44
before sleep 05:06:44
jake
after sleep 05:06:49
before sleep 05:06:49
after sleep 05:06:54
before sleep 05:06:54

(I was running "kill -USR1 11975" in another terminal)

As you see, it works correctly.