summaryrefslogtreecommitdiffstats
path: root/package/base-files
diff options
context:
space:
mode:
authorYuan Tao <ty@wevs.org>2020-09-14 17:19:49 +0800
committerChuanhong Guo <gch981213@gmail.com>2023-02-19 20:04:59 +0800
commitfa08d900d4ec3bf0c2440b336a75f2b9bda29845 (patch)
tree5002c0c2d319984d39202925d2bb87ba7782cf34 /package/base-files
parent01262c921c7cbafc9a32b912e42c58982f47725c (diff)
downloadopenwrt-fa08d900d4ec3bf0c2440b336a75f2b9bda29845.tar.gz
openwrt-fa08d900d4ec3bf0c2440b336a75f2b9bda29845.tar.bz2
openwrt-fa08d900d4ec3bf0c2440b336a75f2b9bda29845.zip
base-files: sysfixtime: Fix time on the fake RTC
On some devices the chip has RTC but no battery save time. This leads back to getting the wrong time and skipping the check of the last file modification date. This commit ensures that the file time is checked even if the RTC exists. which would ordinarily return an approbiate system time used for e.g. certificate generation. Tested-on: NanoPi R2S Signed-off-by: Yuan Tao <ty@wevs.org>
Diffstat (limited to 'package/base-files')
-rwxr-xr-xpackage/base-files/files/etc/init.d/sysfixtime22
1 files changed, 16 insertions, 6 deletions
diff --git a/package/base-files/files/etc/init.d/sysfixtime b/package/base-files/files/etc/init.d/sysfixtime
index aab5b153d0..93f792266a 100755
--- a/package/base-files/files/etc/init.d/sysfixtime
+++ b/package/base-files/files/etc/init.d/sysfixtime
@@ -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