From: LaMont Jones Date: Fri, 21 Sep 2007 20:01:04 +0000 (-0600) Subject: hwclock: Reintroduce hwclockfirst.sh on Debian machines. Closes: #443487 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=848a66d6b8a4fc51b218e80e1c71fe06e85f56ee;p=util-linux hwclock: Reintroduce hwclockfirst.sh on Debian machines. Closes: #443487 If /etc/localtime is a readable file, then set the time in hwclockfirst.sh before mounting the root partition. Many thanks to Ted T'so for the details (found in the bug report.) --- diff --git a/debian/hwclock.sh b/debian/hwclock.sh index 69f45f94..241ec027 100644 --- a/debian/hwclock.sh +++ b/debian/hwclock.sh @@ -12,7 +12,7 @@ # - Added comments to alert users of hwclock issues # and discourage tampering without proper doc reading. -# WARNING: Please read /usr/share/doc/util-linux/README.Debian.hwclock.gz +# WARNING: Please read /usr/share/doc/util-linux/README.Debian.hwclock # or /usr/share/doc/util-linux/README.Debian.hwclock # before changing this file. You risk serious clock # misbehaviour otherwise. @@ -25,6 +25,8 @@ # Default-Stop: 0 6 ### END INIT INFO +FIRST=no # debian/rules sets this to 'yes' when creating hwclockfirst.sh + # Set this to any options you might need to give to hwclock, such # as machine hardware clock type for Alphas. HWCLOCKPARS= @@ -41,6 +43,12 @@ hwclocksh() case "$UTC" in no|"") GMT="--localtime" UTC="" + if [ "X$FIRST" = "Xyes" ] && [ ! -r /etc/localtime ]; then + if [ -z "$TZ" ]; then + log_action_msg "System clock was not updated at this time" + return 1 + fi + fi ;; yes) GMT="--utc" UTC="--utc" @@ -56,32 +64,40 @@ hwclocksh() case "$1" in start) - if [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then + if [ -w /etc ] && [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then echo "0.0 0 0.0" > /etc/adjtime fi - # Uncomment the hwclock --adjust line below if you want - # hwclock to try to correct systematic drift errors in the - # Hardware Clock. - # - # WARNING: If you uncomment this option, you must either make - # sure *nothing* changes the Hardware Clock other than - # hwclock --systohc, or you must delete /etc/adjtime - # every time someone else modifies the Hardware Clock. - # - # Common "vilains" are: ntp, MS Windows, the BIOS Setup - # program. - # - # WARNING: You must remember to invalidate (delete) - # /etc/adjtime if you ever need to set the system clock - # to a very different value and hwclock --adjust is being - # used. - # - # Please read /usr/share/doc/util-linux/README.Debian.hwclock.gz - # before enablig hwclock --adjust. + if [ ! -w /etc/adjtime ]; then + NOADJ="--noadjfile" + else + NOADJ="" + fi - #hwclock --adjust $GMT $BADYEAR - : + if [ "$FIRST" != yes ]; then + # Uncomment the hwclock --adjust line below if you want + # hwclock to try to correct systematic drift errors in the + # Hardware Clock. + # + # WARNING: If you uncomment this option, you must either make + # sure *nothing* changes the Hardware Clock other than + # hwclock --systohc, or you must delete /etc/adjtime + # every time someone else modifies the Hardware Clock. + # + # Common "vilains" are: ntp, MS Windows, the BIOS Setup + # program. + # + # WARNING: You must remember to invalidate (delete) + # /etc/adjtime if you ever need to set the system clock + # to a very different value and hwclock --adjust is being + # used. + # + # Please read /usr/share/doc/util-linux/README.Debian.hwclock + # before enablig hwclock --adjust. + + #hwclock --adjust $GMT $BADYEAR + : + fi if [ "$HWCLOCKACCESS" != no ]; then log_action_msg "Setting the system clock." @@ -89,7 +105,7 @@ hwclocksh() # Copies Hardware Clock time to System Clock using the correct # timezone for hardware clocks in local time, and sets kernel # timezone. DO NOT REMOVE. - /sbin/hwclock --hctosys $GMT $HWCLOCKPARS $BADYEAR + /sbin/hwclock --hctosys $GMT $HWCLOCKPARS $BADYEAR $NOADJ # Announce the local time. verbose_log_action_msg "System Clock set to: `date $UTC`" diff --git a/debian/rules b/debian/rules index c542fc54..a18a1663 100755 --- a/debian/rules +++ b/debian/rules @@ -101,7 +101,12 @@ endif if [ -f debian/util-linux/sbin/hwclock ] ; then \ install -m 755 debian/hwclock.sh debian/util-linux/etc/init.d/hwclock.sh; \ fi -ifneq ($(DISTRO),Debian) +ifeq ($(DISTRO),Debian) + if [ -f debian/util-linux/sbin/hwclock ] ; then \ + install -m 755 debian/hwclock.sh debian/util-linux/etc/init.d/hwclockfirst.sh; \ + sed -i '/^FIRST=/s/no/yes/' debian/util-linux/etc/init.d/hwclockfirst.sh; \ + fi +else if [ -f debian/util-linux/sbin/hwclock ] ; then \ install -m 755 debian/hwclock.udev debian/util-linux/lib/udev/set_hwclock && \ install -m 644 debian/hwclock.rules debian/util-linux/etc/udev/rules.d/85-hwclock.rules; \ diff --git a/debian/util-linux.postinst b/debian/util-linux.postinst index 7886e9ae..c12421e3 100644 --- a/debian/util-linux.postinst +++ b/debian/util-linux.postinst @@ -28,6 +28,9 @@ if [ "$(uname -s)" = "Linux" ]; then update-rc.d -f hwclock.sh remove 2>/dev/null > /dev/null update-rc.d hwclock.sh start 11 S . stop 25 0 6 . > /dev/null update-rc.d -f hwclockfirst.sh remove 2>/dev/null > /dev/null + if [ -f /etc/init.d/hwclockfirst.sh ]; then + update-rc.d hwclockfirst.sh start 8 S . > /dev/null + fi fi fi