tag 342887 + patch thanks See attached patch. It was not completely tested yet, but it seems sane, and it survived some light testing.
Note that hwclock.sh runs much later than I'd like it to, but we need to make sure /usr is mounted, and that means it must run after NFS has had its change of mounting /usr. USER'S GUIDE: 1. Install util-linux with the patch applied 2. Edit hwclockfirst.sh and set TZ to your timezone 3. Change that TZ according to daylight savings time, manually. The TZ hack will be uncessary eventually, and util-linux will be fixed accordingly to not mention TZ anymore in the initscript (dpkg will warn you that the initscript conffile has changed). When that happens, please update the initscript. -- "One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
diff -ruN util-linux-2.12r/debian/hwclock.sh util-linux-2.12r-fix2/debian/hwclock.sh --- util-linux-2.12r/debian/hwclock.sh 2006-01-05 09:17:51.677942513 -0200 +++ util-linux-2.12r-fix2/debian/hwclock.sh 2006-01-05 20:41:58.799569064 -0200 @@ -11,6 +11,12 @@ # during startup/shutdown. # - Added comments to alert users of hwclock issues # and discourage tampering without proper doc reading. +# 2006-01-05 Henrique M. Holschuh <[EMAIL PROTECTED]> +# - Improve message handling +# - Fix FIRST=yes/no invocations of hwclock --hctosys, +# and other minor things +# - Make very sure /etc/adjtime is not used on FIRST=yes +# - Follow symlinks in /etc/adjtime (no reason not to) # WARNING: Please read /usr/share/doc/util-linux/README.Debian.hwclock # before changing this file. You risk serious clock @@ -22,8 +28,15 @@ # as machine hardware clock type for Alphas. HWCLOCKPARS= +# Set this to your timezone if your clock is not in UTC, this hack will go +# away soon. Make sure to use the simplest form for TZ, see tzset(3) for +# details +# e.g. TZ=ABC+03:00 for GMT-3:00, TZ=AAA-05:30 for UTC+05:30 +# +#TZ= + [ ! -x /sbin/hwclock ] && exit 0 -. /etc/default/rcS +[ -r /etc/default/rcS ] && . /etc/default/rcS . /lib/lsb/init-functions verbose_log_action_msg() { [ "$VERBOSE" = no ] || log_action_msg "$@"; } @@ -34,7 +47,9 @@ UTC="" if [ "X$FIRST" = "Xyes" ] && [ ! -r /etc/localtime ]; then if [ -z "$TZ" ]; then - log_action_msg "System clock was not updated at this time" + log_warning_msg "Hardware clock misconfiguration detected!" + log_warning_msg "Hardware clock not in UTC, TZ unset and /etc/localtime unreadable" + log_failure_msg "System clock was not updated at this time" exit 1 fi fi @@ -42,55 +57,65 @@ yes) GMT="--utc" UTC="--utc" ;; - *) log_action_msg "Unknown UTC setting: \"$UTC\""; exit 1 ;; + *) log_warning_msg "Hardware clock misconfiguration detected!" + log_failure_msg "Unknown UTC setting: \"$UTC\""; exit 1 ;; esac case "$BADYEAR" in no|"") BADYEAR="" ;; yes) BADYEAR="--badyear" ;; - *) log_action_msg "unknown BADYEAR setting: \"$BADYEAR\""; exit 1 ;; + *) log_warning_msg "Hardware clock misconfiguration detected!" + log_failure_msg "unknown BADYEAR setting: \"$BADYEAR\""; exit 1 ;; esac case "$1" in start) - if [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then + if [ "$FIRST" != yes ] && [ ! -e /etc/adjtime ]; then + # (will follow symlinks) echo "0.0 0 0.0" > /etc/adjtime fi - 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_daemon_msg "Setting the system clock" + log_action_msg "Setting the system clock from hardware clock" - # 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 + if [ "$FIRST" != yes ]; then + ## + ## RUNS AFTER /usr is mounted, /etc/localtime is in its + ## definitive version, and valid + ## + # + # 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 enabling hwclock --adjust. + # + #/sbin/hwclock --adjust $GMT $HWCLOCKPARS $BADYEAR + + # Copies Hardware Clock time to System Clock using the correct + # timezone for hardware clocks in local time, and sets kernel + # timezone. Updates /etc/adjtime while at it. DO NOT REMOVE. + /sbin/hwclock --hctosys $GMT $HWCLOCKPARS $BADYEAR + else + ## + ## RUNS very early in the boot process, /etc/localtime may be invalid + ## Must not write to /etc, so --noadjfile must be used + ## - if [ "$FIRST" = yes ]; then # Copies Hardware Clock time to System Clock using the correct # timezone for hardware clocks in local time, and sets kernel # timezone. DO NOT REMOVE. @@ -100,19 +125,17 @@ TZ="$TZ" /sbin/hwclock --noadjfile --hctosys $GMT $HWCLOCKPARS $BADYEAR fi - if /sbin/hwclock --show $GMT $HWCLOCKPARS $BADYEAR 2>&1 > /dev/null | + if /sbin/hwclock --noadjfile --show $GMT $HWCLOCKPARS $BADYEAR 2>&1 > /dev/null | grep -q '^The Hardware Clock registers contain values that are either invalid'; then - echo "Invalid system date -- setting to 1/1/2002" - /sbin/hwclock --set --date '1/1/2002 00:00:00' $GMT $HWCLOCKPARS $BADYEAR + log_warning_msg "Invalid system date -- setting to 1/1/2002" + /sbin/hwclock --noadjfile --set --date '1/1/2002 00:00:00' $GMT $HWCLOCKPARS $BADYEAR fi fi - - # Announce the local time. - verbose_log_action_msg "System Clock set. Local time: `date $UTC`" + # Announce system time, always in UTC + verbose_log_action_msg "System Clock set to: `date -u`" else - verbose_log_action_msg "Not setting System Clock" + verbose_log_action_msg "Not setting System Clock, current time: `date -u`" fi - log_end_msg 0 ;; stop|restart|reload|force-reload) # @@ -123,16 +146,12 @@ # clock will not be carried across reboots. # if [ "$HWCLOCKACCESS" != no ]; then - log_daemon_msg "Saving the system clock" - if [ "$GMT" = "-u" ]; then - GMT="--utc" - fi + log_action_msg "Saving the system clock" /sbin/hwclock --systohc $GMT $HWCLOCKPARS $BADYEAR - verbose_log_action_msg "Hardware Clock updated to `date`" + verbose_log_action_msg "Hardware Clock updated to `date $UTC`" else verbose_log_action_msg "Not saving System Clock" fi - log_end_msg 0 ;; show) if [ "$HWCLOCKACCESS" != no ]; then diff -ruN util-linux-2.12r/debian/postinst util-linux-2.12r-fix2/debian/postinst --- util-linux-2.12r/debian/postinst 2006-01-05 09:17:51.688941361 -0200 +++ util-linux-2.12r-fix2/debian/postinst 2006-01-05 20:47:40.971734460 -0200 @@ -22,13 +22,24 @@ fi # hwclock works on all Linux architectures, except s390 (and s390x, of course). +# +# hwclockfirst.sh sets the correct system time when the RTC is not in UTC mode +# or when the kernel is unable to do so by itself for RTCs in UTC time. +# So it must run the *earliest* possible in the boot sequence +# +# hwclock.sh is more of a debug point than anything else, it should run +# after /usr is mounted, to either fix the clock if no timezone information was +# available before that, or to let the user know the system time in the local +# timezone at a moment we are sure the timezones should be sane (after /usr is +# mounted). +# if [ "$(uname -s)" = "Linux" ]; then model=$(uname -m) if [ ${model%x} != "s390" ]; then update-rc.d -f hwclock.sh remove 2>/dev/null > /dev/null - update-rc.d hwclock.sh start 22 S . stop 25 0 6 . > /dev/null + update-rc.d hwclock.sh start 46 S . stop 25 0 6 . > /dev/null update-rc.d -f hwclockfirst.sh remove 2>/dev/null > /dev/null - update-rc.d hwclockfirst.sh start 18 S . > /dev/null + update-rc.d hwclockfirst.sh start 05 S . > /dev/null fi fi