I would like to use the --delaytime option when running the ocsinventory-agent as a daemon, but the --delaytime option does not seems to support specifying the delay in seconds and if I try to specify it with --delaytime 600 (and the server is not available on the first run), then the process goes into an infinite loop with 100% CPU usage and the message "Going to sleep for 0 second(s)" printed in the log.
The problem comes from the fact that the getopt definition of the --delaytime option does not specify that it takes an argument (number of seconds for the delay).
So, the option is considered a boolean option and affected a value of 1 when present.
Later, when the value is used to select a random delay (with rand($delaytime = 1)) it always returns 0 causing the process to retry immediately without delay.
The problem only occurs when trying to specify the delaytime from the command-line. Specifying the delaytime in the configuration file does not shows the problem.
Inventory log file ( optional )
Try to specify a --delaytime 600 when running the agent:
# /usr/bin/ocsinventory-agent -d --delaytime 600
The agent goes into an infinite loop with 0 sec. delay:
# tail -F /var/log/ocsinventory-agent.log
[…]
[Thu Jan 19 13:40:53 2023][error] Cannot establish communication : 500 Can't connect to xxx:443 (Nom ou service inconnu)
[Thu Jan 19 13:40:53 2023][info] Don't send the inventory
[Thu Jan 19 13:40:53 2023][info] Going to sleep for 0 second(s)
[Thu Jan 19 13:40:53 2023][error] Cannot establish communication : 500 Can't connect to xxx:443 (Nom ou service inconnu)
[Thu Jan 19 13:40:53 2023][info] Don't send the inventory
[Thu Jan 19 13:40:53 2023][info] Going to sleep for 0 second(s)
[Thu Jan 19 13:40:53 2023][error] Cannot establish communication : 500 Can't connect to xxx:443 (Nom ou service inconnu)
[Thu Jan 19 13:40:53 2023][info] Don't send the inventory
[Thu Jan 19 13:40:53 2023][info] Going to sleep for 0 second(s)
[Thu Jan 19 13:40:53 2023][error] Cannot establish communication : 500 Can't connect to xxx:443 (Nom ou service inconnu)
[Thu Jan 19 13:40:53 2023][info] Don't send the inventory
[Thu Jan 19 13:40:53 2023][info] Going to sleep for 0 second(s)
[…]
General informations
Operating system : Linux Ubuntu 20.04, Linux Ubuntu 22.04 Perl version : v5.30.0, v5.34.0
OCS Inventory informations
Unix agent version : v2.10.0 (installed from http://deb.ocsinventory-ng.org/ubuntu/)
Problem's description
I would like to use the
--delaytime
option when running theocsinventory-agent
as a daemon, but the--delaytime
option does not seems to support specifying the delay in seconds and if I try to specify it with--delaytime 600
(and the server is not available on the first run), then the process goes into an infinite loop with 100% CPU usage and the message "Going to sleep for 0 second(s)" printed in the log.The problem comes from the fact that the getopt definition of the
--delaytime
option does not specify that it takes an argument (number of seconds for the delay).So, the option is considered a boolean option and affected a value of
1
when present.Later, when the value is used to select a random delay (with
rand($delaytime = 1)
) it always returns0
causing the process to retry immediately without delay.https://github.com/OCSInventory-NG/UnixAgent/blob/9eedb6be4572036617ba1ffb35d16d5b2c1f4db9/lib/Ocsinventory/Agent/Config.pm#L138
https://github.com/OCSInventory-NG/UnixAgent/blob/9eedb6be4572036617ba1ffb35d16d5b2c1f4db9/lib/Ocsinventory/Agent.pm#L269
The getop definition should be :
The problem only occurs when trying to specify the delaytime from the command-line. Specifying the delaytime in the configuration file does not shows the problem.
Inventory log file ( optional )
Try to specify a
--delaytime 600
when running the agent:The agent goes into an infinite loop with 0 sec. delay: