Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CISOfy/lynis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHansHoogerwerf <hans3132@live.nl>2022-10-17 16:46:40 +0300
committerGitHub <noreply@github.com>2022-10-17 16:46:40 +0300
commit98ac5a562ad6f347bcde307d56466b2668251908 (patch)
treefb1910b2c6ffe5f06ffa2c332bd1bb06cfa311dd
parent490d39f58056fd2f0433e11dc7629528587172c3 (diff)
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.
-rw-r--r--include/functions20
1 files 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() {