Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Bootup delay currently broken on master #167

Closed
nemesifier opened this issue Mar 26, 2022 · 11 comments · Fixed by #171
Closed

[bug] Bootup delay currently broken on master #167

nemesifier opened this issue Mar 26, 2022 · 11 comments · Fixed by #171
Labels
bug important Higher priority or release blocker

Comments

@nemesifier
Copy link
Member

See my comment here: b150e65#r69603100

I tried also using the syntax of the previous version but it's not working.

@okraits @devkapilbansal FYI.

Found out thanks to this report #166.

@okraits
Copy link
Member

okraits commented Mar 26, 2022

This looks like a regression. Has it been tested after the changes have been made?

I haven't looked deeper into this but -ne looks like it should be applied to an integer. But "0" isn't an integer, it's a string.

@devkapilbansal
Copy link
Member

I haven't looked deeper into this but -ne looks like it should be applied to an integer. But "0" isn't an integer, it's a string.

I don't think this is the reason. "0" is also treated as an integer 🤔

@nemesifier
Copy link
Member Author

This looks like a regression. Has it been tested after the changes have been made?

It seems it wasn't tested.
But I did test it on Friday.

I haven't looked deeper into this but -ne looks like it should be applied to an integer. But "0" isn't an integer, it's a string.

This is not the issue.
The code block gets executed, but the value of DELAY is always zero I tried this on OpenWrt 21, I tried also the old code and it also does not work, it could have to do something with my device or with OpenWrt 21 / or better said the busybox version used by OpenWrt which may have changed this part of the random generation of numbers.

@okraits
Copy link
Member

okraits commented Mar 28, 2022

I just tested the bootup delay in openwisp-config based on 8b85ca5 on OpenWrt 19.07 and it works fine.

So the issue must have appeared through changes after that.

I'm going to test a more recent version as well.

@okraits
Copy link
Member

okraits commented Mar 28, 2022

I don't know what I'm missing, but it's working fine here also with a quite recent version: d65be8c on OpenWrt 21.02.

The RANDOM function is also working as expected if called from a shell:

root@VR-2020 /etc/config # BOOTUP_DELAY=60
root@VR-2020 /etc/config # echo "$((RANDOM % BOOTUP_DELAY))"
35
root@VR-2020 /etc/config # echo "$((RANDOM % BOOTUP_DELAY))"
51
root@VR-2020 /etc/config # echo "$((RANDOM % BOOTUP_DELAY))"
10
root@VR-2020 /etc/config # echo "$((RANDOM % BOOTUP_DELAY))"
50
root@VR-2020 /etc/config # echo "$((RANDOM % BOOTUP_DELAY))"
34
root@VR-2020 /etc/config # echo "$((RANDOM % BOOTUP_DELAY))"
59

@okraits
Copy link
Member

okraits commented Mar 28, 2022

We enable Ash random support by setting BUSYBOX_DEFAULT_ASH_RANDOM_SUPPORT=y. In upstream OpenWrt this is not enabled: https://github.com/openwrt/openwrt/blob/master/package/utils/busybox/Config-defaults.in#L2994
So we will need to change the implementation to get along without RANDOM.

@nemesifier
Copy link
Member Author

We enable Ash random support by setting BUSYBOX_DEFAULT_ASH_RANDOM_SUPPORT=y. In upstream OpenWrt this is not enabled: https://github.com/openwrt/openwrt/blob/master/package/utils/busybox/Config-defaults.in#L2994 So we will need to change the implementation to get along without RANDOM.

This explains it, thanks.

We could use awk, there's a few examples on stackoverflow, will the seed be good enough?
Alternatively we can add a lua script.

@okraits
Copy link
Member

okraits commented Mar 29, 2022

This works on bash to calculate a kind of random delay value:

okraits:~/ (master✗) $ echo "$((60/100.0*$(head /dev/urandom| tr -dc '[:digit:]' | head -c 2)))"                                [21:21:12]
27.
okraits:~/ (master✗) $ echo "$((60/100.0*$(head /dev/urandom| tr -dc '[:digit:]' | head -c 2)))"                                [21:21:13]
59.399999999999999
okraits:~/ (master✗) $ echo "$((60/100.0*$(head /dev/urandom| tr -dc '[:digit:]' | head -c 2)))"                                [21:21:14]
16.800000000000001
okraits:~/ (master✗) $ echo "$((60/100.0*$(head /dev/urandom| tr -dc '[:digit:]' | head -c 2)))"                                [21:21:15]
25.800000000000001
okraits:~/ (master✗) $ echo "$((60/100.0*$(head /dev/urandom| tr -dc '[:digit:]' | head -c 2)))"                                [21:21:16]
9.5999999999999996

I will try it with ash/busybox tomorrow.

@okraits
Copy link
Member

okraits commented Mar 30, 2022

You can't do float math in ash and bc is not available either. I suggest using a lua script:

  • Call math.randomseed with some input from /dev/urandom
  • Use math.random to get a random number

@nemesifier nemesifier added this to Backlog in OpenWISP Priorities for next releases via automation Apr 19, 2022
@nemesifier nemesifier added bug important Higher priority or release blocker labels Apr 19, 2022
@nemesifier nemesifier moved this from Backlog to To do in OpenWISP Priorities for next releases Apr 19, 2022
@nemesifier nemesifier moved this from To do to In progress in OpenWISP Priorities for next releases Apr 20, 2022
@nemesifier nemesifier moved this from In progress to To do in OpenWISP Priorities for next releases Apr 20, 2022
@devkapilbansal
Copy link
Member

@okraits https://stackoverflow.com/questions/4678836/how-to-generate-random-numbers-under-openwrt

@nemesisdesign This works fine. We can use this instead of RANDOM

@nemesifier
Copy link
Member Author

A solution is almost ready in #171.

OpenWISP Priorities for next releases automation moved this from To do to Done Apr 28, 2022
nemesifier added a commit that referenced this issue Apr 28, 2022
Fixes #167

Co-authored-by: Federico Capoano <f.capoano@openwisp.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug important Higher priority or release blocker
Development

Successfully merging a pull request may close this issue.

3 participants