Busybox sleep 0.5 crashed Ash (but not Bash)

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page Previous  1, 2
Author Message
lexridge
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1082
Location: WV, USA

PostPosted: Sat Mar 16, 2024 17:23    Post subject: Reply with quote
Interesting. Never heard of usleep before. Could be useful. What is also interesting, whenever I execute usleep in a Fedora Linux bash shell, I get this:
Code:

$ usleep
warning: usleep is deprecated, and will be removed in near future!
warning: use "sleep 1e-06" instead...

_________________
Linksys EA8500 (Internet Gateway, AP/VAP) - DD-WRT r53562
Features in use: WDS-AP, Multiple VLANs, Samba, WireGuard, Entware: mqtt, mlocate
Wireless 5ghz only

Netgear R7800 (WDS-AP, WAP, VAP) - DD-WRT r55779
Features in use: multiple VLANs over single trunk port

Linksys EA8500 WDS Station x2 - DD-WRT r55799

Netgear R6400v2 WAP, VAP 2.4ghz only w/VLANs over single trunk port. DD-WRT r55779

OSes: Fedora 38, 9 RPis (2,3,4,5), 20 ESP8266s: Straight from Amiga to Linux in '94, never having owned a Windows PC.

Forum member #248
Sponsor
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Sun Mar 17, 2024 3:18    Post subject: Reply with quote
lexridge wrote:
Interesting. Never heard of usleep before. Could be useful. What is also interesting, whenever I execute usleep in a Fedora Linux bash shell, I get this:
Code:

$ usleep
warning: usleep is deprecated, and will be removed in near future!
warning: use "sleep 1e-06" instead...

Well, both "e" and "-" caused DD-WRT's Ash shell to crash, just like ".".

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
yoyoma2
DD-WRT User


Joined: 24 Sep 2016
Posts: 373

PostPosted: Sun Mar 17, 2024 5:46    Post subject: Reply with quote
Took a peak at the code and found:
    * dd-wrt's busybox has both a shell built-in sleep and /bin/sleep
    * /bin/sleep 0.5 dies and returns to the calling ash shell
    * sleep 0.5 is built-in so when it dies, ash itself dies
    * The code that dies is here (look at 1st line on top)
    * Float support exists but not enabled probably to save space
    * The sleep function is here and called from ash.c when built-in
You would think that busybox would notice when we are inside of a built-in command and skip over the dying part.

Hopefully someone can pick up from here.
lexridge
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1082
Location: WV, USA

PostPosted: Sun Mar 17, 2024 6:56    Post subject: Reply with quote
yoyoma2 wrote:
Took a peak at the code and found

Great find! So it only accepts an integer and not a float, but can accept a float if (re)written properly?

_________________
Linksys EA8500 (Internet Gateway, AP/VAP) - DD-WRT r53562
Features in use: WDS-AP, Multiple VLANs, Samba, WireGuard, Entware: mqtt, mlocate
Wireless 5ghz only

Netgear R7800 (WDS-AP, WAP, VAP) - DD-WRT r55779
Features in use: multiple VLANs over single trunk port

Linksys EA8500 WDS Station x2 - DD-WRT r55799

Netgear R6400v2 WAP, VAP 2.4ghz only w/VLANs over single trunk port. DD-WRT r55779

OSes: Fedora 38, 9 RPis (2,3,4,5), 20 ESP8266s: Straight from Amiga to Linux in '94, never having owned a Windows PC.

Forum member #248
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 14249
Location: Texas, USA

PostPosted: Sun Mar 17, 2024 11:22    Post subject: Reply with quote
Uhm, /bin/sleep is an applet symlinked to busybox, ash is the built-in shell.
Code:
root@WRT3200ACM:~# ls -al /bin/sleep
lrwxrwxrwx    1 root     root             7 Feb 29 14:39 /bin/sleep -> busybox
root@WRT3200ACM:~#

And yes, looking further proves that fractional numbers are not supported as already alluded to.

_________________
"Life is but a fleeting moment, a vapor that vanishes quickly; All is vanity"
Contribute To DD-WRT
Pogo - A minimal level of ability is expected and needed...
DD-WRT Releases 2023 (PolitePol)
DD-WRT Releases 2023 (RSS Everything)

----------------------
Linux User #377467 counter.li.org / linuxcounter.net
yoyoma2
DD-WRT User


Joined: 24 Sep 2016
Posts: 373

PostPosted: Sun Mar 17, 2024 14:12    Post subject: Reply with quote
I built a busybox with CONFIG_FLOAT_DURATION=y and the size is identical to the one I built with float duration disabled (strange, probably needs stripping). The dd-wrt one in /bin is a little smaller but is an older svn revision so hard to compare.

Below I tried sleep 0.5 on dd-wrt's ash, it fails and the shell level drops by one.
I tried sleep 0.5 on my float enabled ash, it works and the shell level remains unchanged.
I tried sleep 0.5 on my float disabled ash, it fails and the shell level drops by one.
Code:
# ls -lSr busybox* /bin/sh /bin/ash /bin/sleep /bin/busybox sh
lrwxrwxrwx    1 root     root             7 Mar 16 23:53 sh -> busybox
lrwxrwxrwx    1 root     root             7 Apr 11  2023 /bin/sleep -> busybox
lrwxrwxrwx    1 root     root             7 Apr 11  2023 /bin/sh -> busybox
lrwxrwxrwx    1 root     root             7 Apr 11  2023 /bin/ash -> busybox
lrwxrwxrwx    1 root     root            13 Mar 17 09:11 busybox -> busybox.float
-rwxr-xr-x    1 root     root        509229 Apr 11  2023 /bin/busybox
-rwxr-xr-x    1 root     root        510488 Mar 17 00:47 busybox.nofloat
-rwxr-xr-x    1 root     root        510488 Mar 17 08:57 busybox.float
# echo SHLVL=$SHLVL
SHLVL=1
# sh


BusyBox v1.36.0 (2023-04-11 11:19:54 EDT) built-in shell (ash)

# echo SHLVL=$SHLVL
SHLVL=2
# sleep 0.5
sh: invalid number '0.5'
# echo SHLVL=$SHLVL
SHLVL=1
# ./sh


BusyBox v1.36.0 (2024-03-17 08:52:52 EDT) built-in shell (ash)

# echo SHLVL=$SHLVL
SHLVL=2
# sleep 0.5
# echo SHLVL=$SHLVL
SHLVL=2
# exit
# echo SHLVL=$SHLVL
SHLVL=1
# ln -sf busybox.nofloat busybox
# ./sh


BusyBox v1.36.0 (2024-03-16 23:13:04 EDT) built-in shell (ash)

# echo SHLVL=$SHLVL
SHLVL=2
# sleep 0.5
sh: invalid number '0.5'
# echo SHLVL=$SHLVL
SHLVL=1
#

Those with openwrt, does sleep 0.5 work or does it give an error message and yet maintain the shell level? Having CONFIG_FLOAT_DURATION disabled is fine but having the entire shell die when it is attempted is not OK.
ho1Aetoo
DD-WRT Guru


Joined: 19 Feb 2019
Posts: 3006
Location: Germany

PostPosted: Sun Mar 17, 2024 14:27    Post subject: Reply with quote
I have already answered that question.

The error occurs not only with 0.5 but also with "sleep --help"

Both work under openwrt without any problems.

Code:
root@OCTEON-TX2:/# sleep 0.5
sleep: invalid number '0.5'
root@OCTEON-TX2:/# sleep --help
BusyBox v1.36.1 (2023-11-14 13:38:11 UTC) multi-call binary.

Usage: sleep [N]...

Pause for a time equal to the total of the args given, where each arg can
have an optional suffix of (s)econds, (m)inutes, (h)ours, or (d)ays
root@OCTEON-TX2:/



Code:
root@DD-WRT:~# sleep 0.5
sh: invalid number '0.5'
Connection to 192.168.1.2 closed.

root@DD-WRT:~# sleep --help
sh: invalid number '--help'
Connection to 192.168.1.2 closed.

_________________
Quickstart guides:
use Pi-Hole as simple DNS-Server with DD-WRT
VLAN configuration via GUI - 1 CPU port
VLAN configuration via GUI - 2 CPU ports (R7800, EA8500 etc)

Routers
Marvell OCTEON TX2 - QHora-322 - OpenWrt 23.05.3 - Gateway
Qualcomm IPQ8065 - R7800 - DD-WRT - WAP
yoyoma2
DD-WRT User


Joined: 24 Sep 2016
Posts: 373

PostPosted: Sun Mar 17, 2024 14:54    Post subject: Reply with quote
Thanks @ho1Aetoo I had seen your openwrt post but still didn't know if float durations were enabled or not. Now I know.

With my dd-wrt build, the type command tells me sleep is a builtin. What does openwrt say. Getting rid of builtin sleep would probably avoid the problem.
Code:
# type sleep
sleep is a shell builtin
# which sleep
/bin/sleep
#
ho1Aetoo
DD-WRT Guru


Joined: 19 Feb 2019
Posts: 3006
Location: Germany

PostPosted: Sun Mar 17, 2024 15:01    Post subject: Reply with quote
Code:
root@OCTEON-TX2:~# type sleep
sleep is /bin/sleep

root@OCTEON-TX2:~# which sleep
/bin/sleep

_________________
Quickstart guides:
use Pi-Hole as simple DNS-Server with DD-WRT
VLAN configuration via GUI - 1 CPU port
VLAN configuration via GUI - 2 CPU ports (R7800, EA8500 etc)

Routers
Marvell OCTEON TX2 - QHora-322 - OpenWrt 23.05.3 - Gateway
Qualcomm IPQ8065 - R7800 - DD-WRT - WAP
yoyoma2
DD-WRT User


Joined: 24 Sep 2016
Posts: 373

PostPosted: Sun Mar 17, 2024 16:56    Post subject: Reply with quote
Thanks @ho1Aetoo. So openwrt chose to disable builtin sleep. Perhaps dd-wrt should do this too. That would be my vote.

The current code for sleep in busybox shows that they know it's broken:

//FIXME: in ash, "sleep 123qwerty" as a builtin aborts the shell
ho1Aetoo
DD-WRT Guru


Joined: 19 Feb 2019
Posts: 3006
Location: Germany

PostPosted: Sun Mar 17, 2024 17:04    Post subject: Reply with quote
Laughing nice find

I will forward it tomorrow when I think of it

_________________
Quickstart guides:
use Pi-Hole as simple DNS-Server with DD-WRT
VLAN configuration via GUI - 1 CPU port
VLAN configuration via GUI - 2 CPU ports (R7800, EA8500 etc)

Routers
Marvell OCTEON TX2 - QHora-322 - OpenWrt 23.05.3 - Gateway
Qualcomm IPQ8065 - R7800 - DD-WRT - WAP
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Mon Mar 18, 2024 14:52    Post subject: Reply with quote
yoyoma2 wrote:
Took a peak at the code and found:
....
Hopefully someone can pick up from here.

Appreciate your effort reading the source codes! Smile

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
yoyoma2
DD-WRT User


Joined: 24 Sep 2016
Posts: 373

PostPosted: Tue Apr 09, 2024 15:52    Post subject: Reply with quote
Logged Bug 16024 in the Busybox project for this issue.
Goto page Previous  1, 2 Display posts from previous:    Page 2 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum