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

Daniel Dickinson openwrt at daniel.thecshore.com
Wed Dec 16 17:40:07 EST 2015


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


--------------080409000403060407060801
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

--------------080409000403060407060801--



More information about the openwrt-devel mailing list