From 267c0eeaeda44bcd02e794548f2cfa121b959869 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 9 Nov 2017 09:57:58 +0100 Subject: [PATCH] net/mwan3: use uptime for ubus age info If the date is changed by ntp the age value of mwan3 on ubus could jitter. Use instead the uptime value from /proc/uptime which will not change during system run. Signed-off-by: Florian Eckert --- net/mwan3/files/lib/mwan3/common.sh | 6 ++++++ net/mwan3/files/usr/libexec/rpcd/mwan3 | 3 ++- net/mwan3/files/usr/sbin/mwan3track | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 net/mwan3/files/lib/mwan3/common.sh diff --git a/net/mwan3/files/lib/mwan3/common.sh b/net/mwan3/files/lib/mwan3/common.sh new file mode 100644 index 0000000000..1af129919c --- /dev/null +++ b/net/mwan3/files/lib/mwan3/common.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +get_uptime() { + local uptime=$(cat /proc/uptime) + echo "${uptime%%.*}" +} diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index 122426f660..a772e133e8 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -3,6 +3,7 @@ . /lib/functions.sh . /lib/functions/network.sh . /usr/share/libubox/jshn.sh +. /lib/mwan3/common.sh MWAN3TRACK_STATUS_DIR="/var/run/mwan3track" @@ -47,7 +48,7 @@ get_mwan3_status() { time_p="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME")" [ -z "${time_p}" ] || { - time_n="$(date +'%s')" + time_n="$(get_uptime)" let age=time_n-time_p } diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 4b744b9fc6..588eb9bf4a 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -1,6 +1,7 @@ #!/bin/sh . /lib/functions.sh +. /lib/mwan3/common.sh LOG="logger -t $(basename "$0")[$$] -p" INTERFACE="" @@ -171,7 +172,7 @@ main() { echo "${lost}" > /var/run/mwan3track/$1/LOST echo "${score}" > /var/run/mwan3track/$1/SCORE echo "${turn}" > /var/run/mwan3track/$1/TURN - echo "$(date +'%s')" > /var/run/mwan3track/$1/TIME + echo "$(get_uptime)" > /var/run/mwan3track/$1/TIME host_up_count=0 sleep "${sleep_time}" & -- 2.30.2