net/mwan3: use uptime for ubus age info
authorFlorian Eckert <redacted>
Thu, 9 Nov 2017 08:57:58 +0000 (09:57 +0100)
committerFlorian Eckert <redacted>
Thu, 16 Nov 2017 08:15:04 +0000 (09:15 +0100)
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 <redacted>
net/mwan3/files/lib/mwan3/common.sh [new file with mode: 0644]
net/mwan3/files/usr/libexec/rpcd/mwan3
net/mwan3/files/usr/sbin/mwan3track

diff --git a/net/mwan3/files/lib/mwan3/common.sh b/net/mwan3/files/lib/mwan3/common.sh
new file mode 100644 (file)
index 0000000..1af1299
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+get_uptime() {
+       local uptime=$(cat /proc/uptime)
+       echo "${uptime%%.*}"
+}
index 122426f660359fcbe50a428eb8c732aad15ee110..a772e133e8cb27421f913f848a90415cedca3a34 100755 (executable)
@@ -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
                }
 
index 4b744b9fc6e2a303a532d7debca6d15d8f993a7e..588eb9bf4aae1ef7d3c442c1fd191fe3d485880e 100755 (executable)
@@ -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}" &
git clone https://git.99rst.org/PROJECT