Bug 15694 - ash built-in sleep behaves differently than external sleep when using traps (busybox 1.36.1)
Summary: ash built-in sleep behaves differently than external sleep when using traps (...
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-13 13:48 UTC by Igor Saric
Modified: 2023-07-13 13:48 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 Igor Saric 2023-07-13 13:48:22 UTC
I noticed something strange during development. Consider this script:

--------------------------------------
#!/bin/ash

busybox sleep 11111 &
_pid1="${!}"

busybox sleep 22222 &
_pid2="${!}"

_trap() {
    echo "killing ${_pid1} ${_pid2}"
    kill -TERM "${_pid1}" "${_pid2}"
    echo "Goodbye"
}

trap '_trap' INT TERM QUIT HUP

echo 'one'
wait || true # press Ctrl-C here
echo 'two'

# works as expected, after wait exits the script waits here for 30s
busybox sleep 30

echo 'three'
--------------------------------------

This opens two external sleep processes and waits for SIGINT, then when the signal is received wait exits and "busybox sleep 30" is executed, and after 30 seconds "three" is printed.

However when using builtin sleep, the script works a bit different.

Replace "busybox sleep 30" with a builtin "sleep 30"

Now, when pressing Ctrl-C, the script will just print "two" and "three" immediately, completely skipping the sleep command.

Not sure why, but since built in sleep was just recently introduced I thought this could be a bug.

I'm using busybox 1.36.1.

Thanks,

Igor