Bug 15694

Summary: ash built-in sleep behaves differently than external sleep when using traps (busybox 1.36.1)
Product: Busybox Reporter: Igor Saric <karabaja4>
Component: OtherAssignee: unassigned
Status: NEW ---    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

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