From b1ad89b1b5d387bdde9527d80f62fcb9c5c4d4e1 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 17 Jun 2022 00:23:00 +0200 Subject: global-functions: rename internal function: $TimeIsSync -> $IsTimeSync --- global-functions | 66 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/global-functions b/global-functions index 79aedb7..9745591 100644 --- a/global-functions +++ b/global-functions @@ -34,6 +34,7 @@ :global IfThenElse; :global IsDefaultRouteReachable; :global IsDNSResolving; +:global IsTimeSync; :global LogPrintExit2; :global MkDir; :global NotificationFunctions; @@ -51,7 +52,6 @@ :global SendNotification2; :global SymbolByUnicodeName; :global SymbolForNotification; -:global TimeIsSync; :global UrlEncode; :global ValidateSyntax; :global VersionToNum; @@ -323,13 +323,13 @@ :global EmailQueue; :global EitherOr; + :global IsTimeSync; :global LogPrintExit2; - :global TimeIsSync; :local AllDone true; :local QueueLen [ :len $EmailQueue ]; - :if ([ $TimeIsSync ] = false) do={ + :if ([ $IsTimeSync ] = false) do={ $LogPrintExit2 debug $0 ("Time is not synced, not flushing.") false; :return false; } @@ -462,6 +462,34 @@ :return true; } +# check if system time is sync +:set IsTimeSync do={ + :global LogPrintExit2; + + :if ([ /system/ntp/client/get enabled ] = true) do={ + :do { + :if ([ /system/ntp/client/get status ] = "synchronized") do={ + :return true; + } + } on-error={ + :if ([ :typeof [ /system/ntp/client/get last-adjustment ] ] = "time") do={ + :return true; + } + } + :return false; + } + + :if ([ /ip/cloud/get ddns-enabled ] = true && [ /ip/cloud/get update-time ] = true) do={ + :if ([ :typeof [ /ip/cloud/get public-address ] ] = "ip") do={ + :return true; + } + :return false; + } + + $LogPrintExit2 debug $0 ("No time source configured! Returning gracefully...") false; + :return true; +} + # log and print with same text, optionally exit :set LogPrintExit2 do={ :local Severity [ :tostr $1 ]; @@ -1110,34 +1138,6 @@ :return ($Return . " "); } -# check if system time is sync -:set TimeIsSync do={ - :global LogPrintExit2; - - :if ([ /system/ntp/client/get enabled ] = true) do={ - :do { - :if ([ /system/ntp/client/get status ] = "synchronized") do={ - :return true; - } - } on-error={ - :if ([ :typeof [ /system/ntp/client/get last-adjustment ] ] = "time") do={ - :return true; - } - } - :return false; - } - - :if ([ /ip/cloud/get ddns-enabled ] = true && [ /ip/cloud/get update-time ] = true) do={ - :if ([ :typeof [ /ip/cloud/get public-address ] ] = "ip") do={ - :return true; - } - :return false; - } - - $LogPrintExit2 debug $0 ("No time source configured! Returning gracefully...") false; - :return true; -} - # url encoding :set UrlEncode do={ :local Input [ :tostr $1 ]; @@ -1256,9 +1256,9 @@ # wait for time to become synced :set WaitTimeSync do={ - :global TimeIsSync; + :global IsTimeSync; - :while ([ $TimeIsSync ] = false) do={ + :while ([ $IsTimeSync ] = false) do={ :delay 1s; } } -- cgit v1.2.3-54-g00ecf