From: Steve McIntyre Date: Fri, 15 Apr 2016 14:48:53 +0000 (+0100) Subject: Change the sanity check on save to use the release date X-Git-Tag: v0.11^0 X-Git-Url: https://git.einval.com/cgi-bin/gitweb.cgi?p=fake-hwclock.git;a=commitdiff_plain;h=f889fd09f2d8d55819dd53785e8bd895866e6628 Change the sanity check on save to use the release date Rather than disallowing saving a clock prior to the last saved state, now compare to a fixed date which corresponds to the release of fake-hwclock itself. Closes: #819019 --- diff --git a/debian/changelog b/debian/changelog index eeac978..a410a58 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +fake-hwclock (0.11) unstable; urgency=medium + + * Change the sanity checking behaviour on save. Rather than disallowing + saving a clock prior to the last saved state, now compare to a fixed + date which corresponds to the release of fake-hwclock itself. + Closes: #819019 + + -- Steve McIntyre <93sam@debian.org> Fri, 15 Apr 2016 12:32:30 +0100 + fake-hwclock (0.10) unstable; urgency=medium * Add a save call to the postinst, to make sure that we save working diff --git a/fake-hwclock b/fake-hwclock index 5c34775..a8e72fa 100755 --- a/fake-hwclock +++ b/fake-hwclock @@ -6,7 +6,7 @@ # NTP is still recommended on these machines to get to real time sync # once more of the system is up and running. # -# Copyright 2012 Steve McIntyre <93sam@debian.org> +# Copyright 2012-2016 Steve McIntyre <93sam@debian.org> # # License: GPLv2, see COPYING @@ -14,6 +14,11 @@ if [ "$FILE"x = ""x ] ; then FILE=/etc/fake-hwclock.data fi +# Midnight on the day of this release, used as a sanity check when +# saving +HWCLOCK_EPOCH="2016-04-15 00:00:00" +HWCLOCK_EPOCH_SEC="1460678400" + COMMAND=$1 if [ "$COMMAND"x = ""x ] ; then COMMAND="save" @@ -27,15 +32,14 @@ fi case $COMMAND in save) if [ -e $FILE ] ; then - SAVED="$(cat $FILE)" - SAVED_SEC=$(date -u -d "$SAVED" '+%s') NOW_SEC=$(date -u '+%s') - if $FORCE || [ $NOW_SEC -ge $SAVED_SEC ] ; then + if $FORCE || [ $NOW_SEC -ge $HWCLOCK_EPOCH_SEC ] ; then date -u '+%Y-%m-%d %H:%M:%S' > $FILE else + echo "Time travel detected!" + echo "fake-hwclock release date is in the future: $HWCLOCK_EPOCH" echo "Current system time: $(date -u '+%Y-%m-%d %H:%M:%S')" - echo "fake-hwclock saved clock information is in the future: $SAVED" - echo "To force the saved system clock backwards anyway, use \"force\"" + echo "To force the saved system clock backwards in time anyway, use \"force\"" fi else date -u '+%Y-%m-%d %H:%M:%S' > $FILE diff --git a/fake-hwclock.8 b/fake-hwclock.8 index 6090c36..9da62ae 100644 --- a/fake-hwclock.8 +++ b/fake-hwclock.8 @@ -34,9 +34,9 @@ If no command is given then fake-hwclock acts as if the save command was used. .SS .TP \fBsave\fP -Save the time to the file. If force is specified fake-hwclock will move the -saved clock either backwards or forwards. Otherwise it will only move -it forwards. +Save the time to the file. As a sanity check, fake-hwclock will not +move the saved clock backwards to a time/date earlier than its own +release date. Use "force" to over-ride this check. .TP \fBload\fP Load the time from the file. If force is specified fake-hwclock will move the