base-files: sysfixtime: Fix time on the fake RTC
[openwrt/staging/aparcar.git] / package / base-files / files / etc / init.d / sysfixtime
index aab5b153d0714fdead6fa70b3f6347dacbbead74..93f792266aac2248ddb6fe54ccca7ca332f2d53a 100755 (executable)
@@ -8,23 +8,33 @@ RTC_DEV=/dev/rtc0
 HWCLOCK=/sbin/hwclock
 
 boot() {
-       start && exit 0
-
-       local maxtime="$(maxtime)"
+       hwclock_load
+       local maxtime="$(find_max_time)"
        local curtime="$(date +%s)"
-       [ $curtime -lt $maxtime ] && date -s @$maxtime
+       if [ $curtime -lt $maxtime ]; then
+               date -s @$maxtime
+               hwclock_save
+       fi
 }
 
 start() {
-       [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -u -f $RTC_DEV
+       hwclock_load
 }
 
 stop() {
+       hwclock_save
+}
+
+hwclock_load() {
+       [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -u -f $RTC_DEV
+}
+
+hwclock_save(){
        [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -u -f $RTC_DEV && \
                logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
 }
 
-maxtime() {
+find_max_time() {
        local file newest
 
        for file in $( find /etc -type f ) ; do