[OpenWrt-Devel] [PATCH] base-files: For sysfixtime use hwclock if RTC available

openwrt at daniel.thecshore.com openwrt at daniel.thecshore.com
Sun Jan 10 02:16:13 EST 2016


From: Daniel Dickinson <openwrt at daniel.thecshore.com>

On systems that have an RTC prefer it to the file-based
time fixup (i.e. use hwclock when there is a permanent
clock instead of the faked up time logic that is needed
when there is not RTC).

Signed-off-by: Daniel Dickinson <openwrt at daniel.thecshore.com>
---
 package/base-files/files/etc/init.d/sysfixtime | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/package/base-files/files/etc/init.d/sysfixtime b/package/base-files/files/etc/init.d/sysfixtime
index 4010e06..f40bb6e 100755
--- a/package/base-files/files/etc/init.d/sysfixtime
+++ b/package/base-files/files/etc/init.d/sysfixtime
@@ -2,10 +2,27 @@
 # Copyright (C) 2013-2014 OpenWrt.org
 
 START=00
+STOP=90
 
 boot() {
-	local curtime="$(date +%s)"
-	local maxtime="$(find /etc -type f -exec date -r {} +%s \; | sort -nr | head -n1)"
-	[ $curtime -lt $maxtime ] && date -s @$maxtime
+	if [ -e /dev/rtc ]; then
+		hwclock -s
+        else
+		local curtime="$(date +%s)"
+		local maxtime="$(find /etc -type f -exec date -r {} +%s \; | sort -nr | head -n1)"
+		[ $curtime -lt $maxtime ] && date -s @$maxtime
+	fi
+}
+
+start() {
+	if [ -e /dev/rtc ]; then
+		hwclock -s
+	fi
+}
+
+stop() {
+	if [ -e /dev/rtc ]; then
+		hwclock -w
+	fi
 }
 
-- 
2.4.3
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list