From 98ac5a562ad6f347bcde307d56466b2668251908 Mon Sep 17 00:00:00 2001 From: HansHoogerwerf Date: Mon, 17 Oct 2022 15:46:40 +0200 Subject: Verify the linux OS supports nanoseconds Add extra check to verify the linux OS supports nanoseconds. This might not be the case with certain busybox implementations. --- include/functions | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/include/functions b/include/functions index 5b211707..db4c7ef8 100644 --- a/include/functions +++ b/include/functions @@ -2562,15 +2562,17 @@ GetTimestamp() { ts=0 - case "${OS}" in - "Linux") - ts=$(date "+%s%N") - ;; - *) - ts=$(date "+%s") - ;; - esac - echo $ts + # Detect if the implementation of date supports nanoseconds, + if [ "${OS}" = "Linux" ]; then + current_nanoseconds=$(date "+%N") + # Verify if the result of the command is a number + if [ -n "$current_nanoseconds" ] && [ "$current_nanoseconds" -eq "$current_nanoseconds" ] 2>/dev/null; then + ts=$(date "+%s%N") + else + ts=$(date "+%s") + fi + fi + echo $ts } Register() { -- cgit v1.2.3 From ff26dca83a0f788ac7853b73e9d42cec49846aa7 Mon Sep 17 00:00:00 2001 From: HansHoogerwerf Date: Mon, 17 Oct 2022 16:24:59 +0200 Subject: Fix simple mistake --- include/functions | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/include/functions b/include/functions index db4c7ef8..5ae9b978 100644 --- a/include/functions +++ b/include/functions @@ -2562,17 +2562,19 @@ GetTimestamp() { ts=0 - # Detect if the implementation of date supports nanoseconds, - if [ "${OS}" = "Linux" ]; then - current_nanoseconds=$(date "+%N") - # Verify if the result of the command is a number + # Detect if the implementation of date supports nanoseconds, + if [ "${OS}" = "Linux" ]; then + current_nanoseconds=$(date "+%N") + # Verify if the result of the command is a number if [ -n "$current_nanoseconds" ] && [ "$current_nanoseconds" -eq "$current_nanoseconds" ] 2>/dev/null; then ts=$(date "+%s%N") else - ts=$(date "+%s") - fi + ts=$(date "+%s") + fi + else + ts=$(date "+%s") fi - echo $ts + echo $ts } Register() { -- cgit v1.2.3 From bbe135d56f13f3c05a4a328c504639c6568de8b2 Mon Sep 17 00:00:00 2001 From: HansHoogerwerf Date: Mon, 17 Oct 2022 16:27:21 +0200 Subject: Fix space --- include/functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/functions b/include/functions index 5ae9b978..38cc46b3 100644 --- a/include/functions +++ b/include/functions @@ -2567,7 +2567,7 @@ current_nanoseconds=$(date "+%N") # Verify if the result of the command is a number if [ -n "$current_nanoseconds" ] && [ "$current_nanoseconds" -eq "$current_nanoseconds" ] 2>/dev/null; then - ts=$(date "+%s%N") + ts=$(date "+%s%N") else ts=$(date "+%s") fi -- cgit v1.2.3