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

No value in $RANDOM #800

Closed
AndyMcSchopf opened this issue Nov 10, 2020 · 16 comments · Fixed by #991
Closed

No value in $RANDOM #800

AndyMcSchopf opened this issue Nov 10, 2020 · 16 comments · Fixed by #991

Comments

@AndyMcSchopf
Copy link

As stated here: lime-users-maillinglist
I found out, that in OpenWRT snapshot there is no value initialized for the Variable $RANDOM which is used in crontab for LiMe.

@AndyMcSchopf
Copy link
Author

I checked this point and it seems that this bug is closed in SNAPSHOT and the actual branch 21.02.

@ilario
Copy link
Member

ilario commented Mar 4, 2021

Thanks for checking!

@rallep71
Copy link

rallep71 commented Mar 6, 2021

I checked this point and it seems that this bug is closed in SNAPSHOT and the actual branch 21.02.

Question: can we include this in the current version 19.07.7 or do we have to wait until version 21.02?

@ilario
Copy link
Member

ilario commented Mar 8, 2021

Question: can we include this in the current version 19.07.7 or do we have to wait until version 21.02?

Eh?
Define "this" please.
Is the bug present in 19.07.7?

@AndyMcSchopf
Copy link
Author

@rallep71 : This bug was only in master, please check my mail on the mailinglist - there is/was no problem in 19.07.x ;-)

@rallep71
Copy link

rallep71 commented Mar 8, 2021

Question: can we include this in the current version 19.07.7 or do we have to wait until version 21.02?

Eh?
Define "this" please.
Is the bug present in 19.07.7?

Logfile, 19.07.7
Mon Mar 8 13:35:00 2021 cron.info crond[936]: USER root pid 23379 cmd ((sleep $(($RANDOM % 120)); shared-state sync dnsmasq-leases &> /dev/null)&)
Mon Mar 8 13:35:00 2021 cron.info crond[936]: USER root pid 23380 cmd ((sleep $(($RANDOM % 120)); shared-state sync babeld-hosts &> /dev/null)&)
Mon Mar 8 13:35:00 2021 cron.info crond[936]: USER root pid 23381 cmd ((sleep $(($RANDOM % 120)); shared-state sync bat-hosts &> /dev/null)&)
Mon Mar 8 13:35:00 2021 cron.info crond[936]: USER root pid 23382 cmd ((sleep $(($RANDOM % 120)); shared-state sync nodes_and_links &> /dev/null)&)
Mon Mar 8 13:35:00 2021 cron.info crond[936]: USER root pid 23383 cmd ((sleep $(($RANDOM % 120)); shared-state sync dnsmasq-hosts &> /dev/null)&)
Mon Mar 8 13:36:00 2021 cron.info crond[936]: USER root pid 23763 cmd ((for dataFile in /var/shared-state/data/* ; do shared-state bleach $(basename $dataFile .json); done &> /dev/null)&)
Mon Mar 8 13:38:00 2021 cron.info crond[936]: USER root pid 24374 cmd ((for dataFile in /var/shared-state/data/* ; do shared-state bleach $(basename $dataFile .json); done &> /dev/null)&)
Mon Mar 8 13:40:00 2021 cron.info crond[936]: USER root pid 24440 cmd ((sleep $(($RANDOM % 120)); shared-state sync dnsmasq-leases &> /dev/null)&)
Mon Mar 8 13:40:00 2021 cron.info crond[936]: USER root pid 24441 cmd ((sleep $(($RANDOM % 600)); check-date-http &> /dev/null)&)
Mon Mar 8 13:40:00 2021 cron.info crond[936]: USER root pid 24442 cmd ((sleep $(($RANDOM % 120)); shared-state sync babeld-hosts &> /dev/null)&)
Mon Mar 8 13:40:00 2021 cron.info crond[936]: USER root pid 24443 cmd ((sleep $(($RANDOM % 120)); shared-state sync bat-hosts &> /dev/null)&)
Mon Mar 8 13:40:00 2021 cron.info crond[936]: USER root pid 24445 cmd ((sleep $(($RANDOM % 120)); shared-state sync nodes_and_links &> /dev/null)&)
Mon Mar 8 13:40:00 2021 cron.info crond[936]: USER root pid 24446 cmd ((sleep $(($RANDOM % 120)); shared-state sync dnsmasq-hosts &> /dev/null)&)
Mon Mar 8 13:40:00 2021 cron.info crond[936]: USER root pid 24447 cmd ((for dataFile in /var/shared-state/data/* ; do shared-state bleach $(basename $dataFile .json); done &> /

@spiccinini
Copy link
Contributor

@rallep71 that log is normal (no error). The variables are replaced on execution, but they are loged "as they are" in the cron config.

@rallep71
Copy link

rallep71 commented Mar 8, 2021

@rallep71 that log is normal (no error). The variables are replaced on execution, but they are loged "as they are" in the cron config.

Thank you for the clarification!!! Mercy

@spiccinini
Copy link
Contributor

Thank you and @AndyMcSchopf for the feedback and being alert of posible problems!

@ilario
Copy link
Member

ilario commented Dec 28, 2022

On the Matrix/Element chat, Pony wrote that the $RANDOM is empty, again.

This seems related to the lack of effect of the BUSYBOX_CONFIG_ASH_RANDOM_SUPPORT, that gets set by a number of LibreMesh packages if they are included at compilation time in the buildroot.

This is not the only variable that can be not present when alternative installation methods are used (e.g. ImageBuilder SDK or installing packages one by one via OPKG), more of these configuration options have been listed here:
http://web.archive.org/web/20221228204719/https://listas.librerouter.org/archives/list/lime-users@lists.libremesh.org/message/AWSAUYSKEXN5GNORLIYHPJP5LIWAC5EQ/

@ilario ilario reopened this Dec 28, 2022
@ilario
Copy link
Member

ilario commented Dec 28, 2022

In my opinion we should stop using $RANDOM and use either math.random from Lua where possible (some care has to be employed for this to work, see https://stackoverflow.com/questions/21806967/lua-math-random) or some handmade pseudorandom number generator. Actually, we already have a pseudorandom generator that can be instructed to output numeric strings:

--! returns a random string. filter is an optional function to reduce the possible characters.
--! by default the filter allows all the alphanumeric characters
function utils.random_string(length, filter)

But the $RANDOM variable gets used in shell scripts, so it would be more convenient to avoid calling Lua things. We could use this: https://stackoverflow.com/a/4508380

@pony1k
Copy link
Contributor

pony1k commented Dec 29, 2022

Turns out that BUSYBOX_CUSTOM has to be selected to make selection of BUSYBOX_CONFIG_ASH_RANDOM_SUPPORT possible. Maybe this could be fixed by making the packages that use $RANDOM dependent of BUSYBOX_CUSTOM?
We could use $(head -c 2 /dev/urandom | hexdump -e '2/2 "%u""\n"') instead of $RANDOM. It generates numbers from 0 to 65535.

@ilario ilario added this to the 2020.2 milestone Feb 23, 2023
@ilario
Copy link
Member

ilario commented Mar 13, 2023

Thanks @pony1k !
hexdump from Busybox seems included in every OpenWrt image, so the command you propose is perfect :D

@ilario
Copy link
Member

ilario commented Mar 14, 2023

This has been addressed in #980, check it out

@ilario
Copy link
Member

ilario commented Mar 26, 2023

Just proposed a package with an alternative command that can be used here:
openwrt/packages#20728

@ilario
Copy link
Member

ilario commented Apr 26, 2023

$RANDOM has been activated in OpenWrt with openwrt/openwrt#12465 and openwrt/openwrt@8f427f1, should be available in the next 23.something release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment