From ab6da336e8b66c33256bcb3c952d86861a3c7f68 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Fri, 6 May 2011 12:43:57 -0500 Subject: [PATCH] targets/amd64/SS4200: add patch to detect and mitigate clockskew issues on boot If the machine's clock is reset to before the firmware image was assmbled (bad cmos battery), a subsequent save will wipe out all changes made since boot, as those files will be dated prior to the anchor file. This patch detects that condition as soon as the /conf filesystem is moutned, and force-sets the clock to a time 60 seconds after the most recent mtime of the anchor file, the base confpack, or the saved confpack (/conf/default). --- .../etc_rc.initdiskless-fix-clockskew.patch | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 targets/amd64/SS4200/config/patch/etc_rc.initdiskless-fix-clockskew.patch diff --git a/targets/amd64/SS4200/config/patch/etc_rc.initdiskless-fix-clockskew.patch b/targets/amd64/SS4200/config/patch/etc_rc.initdiskless-fix-clockskew.patch new file mode 100644 index 0000000..01d720c --- /dev/null +++ b/targets/amd64/SS4200/config/patch/etc_rc.initdiskless-fix-clockskew.patch @@ -0,0 +1,33 @@ +--- etc/rc.initdiskless 2011-01-23 05:59:54.000000000 -0600 ++++ etc/rc.initdiskless 2011-05-06 12:40:10.940259210 -0500 +@@ -337,9 +337,30 @@ + + # NFS remount + handle_remount $j ++ ++ # Keep track of the most recent timestamp for clockskew detection ++ stamp="$(/usr/bin/stat -f %Um "$j")" ++ [ "${stamp}" -gt "${newest:-0}" ] && newest="${stamp}" ++ # + done + done + ++# ++# Check for clock skew, to make sure the local timestamp is newer than ++# the last saveconfig or the date of the image ++stamp="$(/usr/bin/stat -f %Um "/COPYRIGHT")" ++[ "${stamp}" -gt "${newest:-0}" ] && newest="${stamp}" ++if [ "${newest}" -gt "$(/bin/date +%s)" ] ++then ++ # Clock skew detected! Attempt to correct ++ correction="$(( ${newest} + 60 ))" ++ printf "Clock skew detected!\n" >&2 ++ printf " Now (%s) is before newest (%s)\n" "$(/bin/date)" "$(/bin/date -jf %s "${newest}")" >&2 ++ printf "Clock reset to %s\n" "$(/bin/date -f %s "${correction}")" >&2 ++ printf "Run ntpd or ntpdate or manually set correct time!\n" >&2 ++fi ++# ++ + # - Create all required MFS filesystems and populate them from + # our templates. Support both a direct template and a dir.cpio.gz + # archive. Support dir.remove files containing a list of relative -- 2.42.0