ddns-scripts: refactor get_uptime() and avoid cat in sub-shell
authorPaul Donald <[email protected]>
Thu, 28 Nov 2024 02:43:33 +0000 (03:43 +0100)
committerFlorian Eckert <[email protected]>
Thu, 10 Apr 2025 07:34:38 +0000 (09:34 +0200)
no sub-shell is spawned to get uptime.

Signed-off-by: Paul Donald <[email protected]>
net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_functions.sh

index d64ad8c26b251953c6bedde12420b1ac68c89cac..297388a15981fa6e4a286bed77a9345647ffdaea 100644 (file)
@@ -1210,9 +1210,9 @@ get_registered_ip() {
 
 get_uptime() {
        # $1    Variable to store result in
-       [ $# -ne 1 ] && write_log 12 "Error calling 'verify_host_port()' - wrong number of parameters"
-       local __UPTIME=$(cat /proc/uptime)
-       eval "$1=\"${__UPTIME%%.*}\""
+       [ $# -ne 1 ] && write_log 12 "Error calling 'get_uptime()' - requires exactly 1 argument."
+       read -r uptime < /proc/uptime
+       eval "$1=\"${uptime%%.*}\""
 }
 
 trap_handler() {