Package: util-linux Version: 2.20.1-1.2 Severity: normal Tags: patch The attached patch, changed slightly from the one already Ccd to you which was sent to -devel, cleans up a number of issues with the hwclock support in util-linux. They are all documented in the changelog in the attached patch.
I've tested this for systems in a non-GMT timezone (PST) with the hardware clock in both UTC and LOCAL time, and with and without the udev support enabled. It works perfectly in all these cases. I've asked for testing in case there are any corner cases not handled here, but it looks quite straight- forward, so there shouldn't be any major issues here. The patch is against current git master; the version checks in the maintainer scripts are for the current changelog version, so would need updating if not included in this version. Thanks, Roger -- System Information: Debian Release: wheezy/sid APT prefers unstable APT policy: (550, 'unstable'), (500, 'testing'), (400, 'experimental') Architecture: amd64 (x86_64) Kernel: Linux 3.2.0-1-amd64 (SMP w/4 CPU cores) Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Versions of packages util-linux depends on: ii debconf [debconf-2.0] 1.5.41 ii dpkg 1.16.2~wipmultiarch ii initscripts 2.88dsf-23 ii install-info 4.13a.dfsg.1-8 ii libblkid1 2.20.1-1.2 ii libc6 2.13-26 ii libncurses5 5.9-4 ii libselinux1 2.1.0-4.1 ii libslang2 2.2.4-6 ii libtinfo5 5.9-4 ii libuuid1 2.20.1-1.2 ii lsb-base 3.2-28.1 ii tzdata 2011n-2 ii zlib1g 1:1.2.6.dfsg-1 util-linux recommends no packages. Versions of packages util-linux suggests: pn dosfstools 3.0.12-1 pn kbd 1.15.3-7 pn util-linux-locales <none> -- debconf information excluded
>From ca4254c92fc097c3924e1f448f4e00ee47485645 Mon Sep 17 00:00:00 2001 From: Roger Leigh <[email protected]> Date: Fri, 17 Feb 2012 12:38:32 +0000 Subject: [PATCH] debian: Drop UTC in favour of adjtime and add /e/d/hwclock --- debian/changelog | 30 +++++++++++++ debian/hwclock-set | 21 ++++++--- debian/hwclock.5 | 39 +++++++++++++++++ debian/hwclock.default | 19 ++++++++ debian/hwclock.sh | 103 +++++++++++--------------------------------- debian/rules | 11 +---- debian/util-linux.postinst | 15 ++++++ debian/util-linux.preinst | 25 +++++++++++ 8 files changed, 169 insertions(+), 94 deletions(-) create mode 100644 debian/hwclock.5 create mode 100644 debian/hwclock.default diff --git a/debian/changelog b/debian/changelog index 8ffed83..072ef2d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -39,6 +39,36 @@ util-linux (2.20.1-2) unstable; urgency=low * Enable hardened build flags. Closes: #653856 + [Roger Leigh] + * Improve handling of the hardware clock + - Remove redundant hwclockfirst.sh and hwclock.sh. The reason for + this redundant script existing (/etc/localtime not being present + until after /usr was mounted AFAICT) no longer exists. The + hwclock script has been adjusted to run before checkroot. + - Migrate existing + UTC= setting in /etc/default/rcS to UTC/LOCAL in /etc/adjtime. + This removes needless duplication of the setting, and presents the + behaviour of hwclock being overridden, and its configuration + overwritten every shutdown. Closes: #554345 + - The hwclock init scripts no longer use /etc/adjtime instead of + the --utc and --localtime options (based on the UTC setting). + - Add /etc/default/hwclock and hwclock(5) which permit + configuration without editing the initscript, and also document + all the undocumented variables used by the scripts. Closes: + #481357, #659654 + - The udev hwclock-set script runs hwclock --tzset unconditionally + in all cases (it's a no-op for UTC). + - The user running "hwclock --systohc (--utc|--localtime)" is now + handled correctly. The clock state is recorded in /etc/adjtime + and correctly handled on system restart. This means the UTC + setting in /etc/default/rcS doesn't create problems by requiring + two separate changes (changing the UTC setting and running + hwclock) to do the same thing. + - systemd uses /etc/adjtime as for hwclock to store the hardware + clock UTC/LOCAL configuration. This change means there's a + single place to store the hardware clock configuration for all + init systems. + -- LaMont Jones <[email protected]> Thu, 09 Feb 2012 10:06:42 -0700 util-linux (2.20.1-1.2) unstable; urgency=low diff --git a/debian/hwclock-set b/debian/hwclock-set index fc1698f..dfbf501 100644 --- a/debian/hwclock-set +++ b/debian/hwclock-set @@ -10,12 +10,19 @@ fi if [ -f /etc/default/rcS ] ; then . /etc/default/rcS -fi +fi + +# These defaults are user-overridable in /etc/default/hwclock +BADYEAR=no +HWCLOCKACCESS=yes +HWCLOCKPARS= +HCTOSYS_DEVICE=rtc0 +if [ -f /etc/default/hwclock ] ; then + . /etc/default/hwclock +fi -if [ yes != "$UTC" ] ; then - if [ yes = "$BADYEAR" ] ; then - /sbin/hwclock --rtc=$dev --systz --localtime --noadjfile --badyear - else - /sbin/hwclock --rtc=$dev --systz --localtime --noadjfile - fi +if [ yes = "$BADYEAR" ] ; then + /sbin/hwclock --rtc=$dev --systz --badyear +else + /sbin/hwclock --rtc=$dev --systz fi diff --git a/debian/hwclock.5 b/debian/hwclock.5 new file mode 100644 index 0000000..3de97e0 --- /dev/null +++ b/debian/hwclock.5 @@ -0,0 +1,39 @@ +.TH HWCLOCK 5 "Feb 2012" "" "Debian Administrator's Manual" +.SH NAME +hwclock \- variables that affect the behaviour of the hwclock boot script +.SH DESCRIPTION +The +.I /etc/default/rcS +file contains variable settings in POSIX format: +.IP "" .5i +VAR=VAL +.PP +Only one assignment is allowed per line. +Comments (starting with '#') are also allowed. + +.SH OPTIONS +The following variables can be set. + +.IP \fBBADYEAR\fP +This is used to specify that the hardware clock is incapable of storing +years outside the range of 1994-1999. Set to \fByes\fP if the hardware is +broken or \fBno\fP if working correctly. + +.IP \fBHWCLOCKACCESS\fP +If the hardware clock is not accessible, set to \fBno\fP, in which +case hwclock will not be run. Otherwise, set to \fByes\fP. + +.IP \fBHWCLOCKPARS\fP +Additional options for hwclock. Unset by default. For example, this +may be use to specify the machine hardware clock type for Alphas. + +.IP \fBHCTOSYS_DEVICE\fP +The hardware clock device you want to use. Defaults to \fBrtc0\fP. +It should probably match the CONFIG_RTC_HCTOSYS_DEVICE kernel config +option. + +.SH AUTHOR +Roger Leigh <[email protected]> + +.SH SEE ALSO +.BR hwclock "(8), rcS "(5)." diff --git a/debian/hwclock.default b/debian/hwclock.default new file mode 100644 index 0000000..dcf5451 --- /dev/null +++ b/debian/hwclock.default @@ -0,0 +1,19 @@ +# Defaults for the hwclock init script. See hwclock(5) and hwclock(8). + +# This is used to specify that the hardware clock incapable of storing +# years outside the range of 1994-1999. Set to yes if the hardware is +# broken or no if working correctly. +#BADYEAR=no + +# Set this to yes if it is possible to access the hardware clock, +# or no if it is not. +#HWCLOCKACCESS=yes + +# Set this to any options you might need to give to hwclock, such +# as machine hardware clock type for Alphas. +#HWCLOCKPARS= + +# Set this to the hardware clock device you want to use, it should +# probably match the CONFIG_RTC_HCTOSYS_DEVICE kernel config option. +#HCTOSYS_DEVICE=rtc0 + diff --git a/debian/hwclock.sh b/debian/hwclock.sh index 1427bac..076ec47 100644 --- a/debian/hwclock.sh +++ b/debian/hwclock.sh @@ -1,6 +1,5 @@ #!/bin/sh -# hwclock.sh Set and adjust the CMOS clock, according to the UTC -# setting in /etc/default/rcS (see also rcS(5)). +# hwclock.sh Set and adjust the CMOS clock. # # Version: @(#)hwclock.sh 2.00 14-Dec-1998 [email protected] # @@ -11,6 +10,10 @@ # during startup/shutdown. # - Added comments to alert users of hwclock issues # and discourage tampering without proper doc reading. +# 2012-02-16 Roger Leigh <[email protected]> +# - Use the UTC/LOCAL setting in /etc/adjtime rather than +# the UTC setting in /etc/default/rcS. Additionally +# source /etc/default/hwclock to permit configuration. # WARNING: Please read /usr/share/doc/util-linux/README.Debian.hwclock # before changing this file. You risk serious clock @@ -18,47 +21,28 @@ ### BEGIN INIT INFO # Provides: hwclock -# Required-Start: checkroot +# Required-Start: mountdevsubfs # Required-Stop: $local_fs # Default-Start: S +# X-Start-Before: checkroot # 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. +# These defaults are user-overridable in /etc/default/hwclock +BADYEAR=no +HWCLOCKACCESS=yes HWCLOCKPARS= - -# Set this to the hardware clock device you want to use, it should -# probably match the CONFIG_RTC_HCTOSYS_DEVICE kernel config option. HCTOSYS_DEVICE=rtc0 hwclocksh() { [ ! -x /sbin/hwclock ] && return 0 [ ! -r /etc/default/rcS ] || . /etc/default/rcS + [ ! -r /etc/default/hwclock ] || . /etc/default/hwclock . /lib/lsb/init-functions verbose_log_action_msg() { [ "$VERBOSE" = no ] || log_action_msg "$@"; } - [ "$GMT" = "-u" ] && UTC="yes" - 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" - ;; - *) log_action_msg "Unknown UTC setting: \"$UTC\""; return 1 ;; - esac - case "$BADYEAR" in no|"") BADYEAR="" ;; yes) BADYEAR="--badyear" ;; @@ -67,52 +51,29 @@ hwclocksh() case "$1" in start) - if [ -d /run/udev ] || [ -d /dev/.udev ]; then - return 0 - fi - + # If the admin deleted the hwclock config, create a blank + # template with the defaults. if [ -w /etc ] && [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then - echo "0.0 0 0.0" > /etc/adjtime - fi - - if [ ! -w /etc/adjtime ]; then - NOADJ="--noadjfile" - else - NOADJ="" + printf "0.0 0 0.0\n0\nUTC" > /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 enabling hwclock --adjust. - - #/sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --adjust $GMT $BADYEAR - : + if [ -d /run/udev ] || [ -d /dev/.udev ]; then + return 0 fi if [ "$HWCLOCKACCESS" != no ]; then log_action_msg "Setting the system clock" + # Just for reporting. + if head -n 3 /etc/adjtime | tail -n 1 | grep -q '^UTC$' ; then + UTC="--utc" + else + UTC= + fi # Copies Hardware Clock time to System Clock using the correct # timezone for hardware clocks in local time, and sets kernel # timezone. DO NOT REMOVE. - if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --hctosys $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then + if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --hctosys $HWCLOCKPARS $BADYEAR; then # Announce the local time. verbose_log_action_msg "System Clock set to: `date $UTC`" else @@ -130,18 +91,10 @@ hwclocksh() # WARNING: If you disable this, any changes to the system # clock will not be carried across reboots. # - if [ ! -w /etc/adjtime ]; then - NOADJ="--noadjfile" - else - NOADJ="" - fi if [ "$HWCLOCKACCESS" != no ]; then log_action_msg "Saving the system clock" - if [ "$GMT" = "-u" ]; then - GMT="--utc" - fi - if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --systohc $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then + if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --systohc $HWCLOCKPARS $BADYEAR; then verbose_log_action_msg "Hardware Clock updated to `date`" fi else @@ -149,14 +102,8 @@ hwclocksh() fi ;; show) - if [ ! -w /etc/adjtime ]; then - NOADJ="--noadjfile" - else - NOADJ="" - fi - if [ "$HWCLOCKACCESS" != no ]; then - /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --show $GMT $HWCLOCKPARS $BADYEAR $NOADJ + /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --show $HWCLOCKPARS $BADYEAR fi ;; *) diff --git a/debian/rules b/debian/rules index 6e08382..86f4452 100755 --- a/debian/rules +++ b/debian/rules @@ -124,15 +124,8 @@ endif install -m 644 debian/mime.util-linux debian/util-linux/usr/lib/mime/packages/util-linux if [ -f debian/util-linux/sbin/hwclock ] ; then \ install -m 755 debian/hwclock.sh debian/util-linux/etc/init.d/hwclock.sh; \ - install -m 755 debian/hwclock.sh debian/util-linux/etc/init.d/hwclockfirst.sh; \ - sed -i -e '/^FIRST=/s/no/yes/' -e '/Provides:/s/ck/ckfirst/' \ - -e '/Required-Start:/s/checkroot/mountdevsubfs/' \ - -e '/Required-Start:/a# Required-Stop:' -e '/Required-Stop:/d' \ - -e '/Default-Start:/a# X-Start-Before: checkroot' \ - -e '/Default-Start:/a# Default-Stop:' -e '/Default-Stop:/d' \ - debian/util-linux/etc/init.d/hwclockfirst.sh; \ - fi - if [ -f debian/util-linux/sbin/hwclock ] ; then \ + install -m 644 debian/hwclock.default debian/util-linux/etc/default/hwclock; \ + install -m 644 debian/hwclock.5 debian/util-linux/usr/share/man/man5; \ install -m 644 debian/hwclock.rules debian/util-linux/lib/udev/rules.d/85-hwclock.rules; \ install -m 755 debian/hwclock-set debian/util-linux/lib/udev/hwclock-set; \ fi diff --git a/debian/util-linux.postinst b/debian/util-linux.postinst index b536eac..931c03f 100644 --- a/debian/util-linux.postinst +++ b/debian/util-linux.postinst @@ -31,6 +31,21 @@ if [ "$(uname -s)" = "Linux" ]; then fi fi +# Do a one-time migration of the local time setting to /etc/adjtime +if dpkg --compare-versions "$2" lt "2.20.1-2"; then + if [ -f /etc/default/rcS ]; then + . /etc/default/rcS + fi + if [ ! -e /etc/adjtime ]; then + printf "0.0 0 0.0\n0\nUTC" > /etc/adjtime + fi + if [ "$UTC" = "no" ]; then + sed -i -e 's:^UTC$:LOCAL:' /etc/adjtime + else + sed -i -e 's:^LOCAL$:UTC:' /etc/adjtime + fi +fi + if [ -x /usr/sbin/update-mime ]; then update-mime fi diff --git a/debian/util-linux.preinst b/debian/util-linux.preinst index a6a6527..6bf6167 100644 --- a/debian/util-linux.preinst +++ b/debian/util-linux.preinst @@ -2,6 +2,26 @@ set -e +# Remove a no-longer used conffile +rm_conffile() { + local PKGNAME="$1" + local CONFFILE="$2" + + [ -e "$CONFFILE" ] || return 0 + + local md5sum="$(md5sum $CONFFILE | sed -e 's/ .*//')" + local old_md5sum="$(dpkg-query -W -f='${Conffiles}' $PKGNAME | \ + sed -n -e "\' $CONFFILE ' { s/ obsolete$//; s/.* //; p }")" + if [ "$md5sum" != "$old_md5sum" ]; then + echo "Obsolete conffile $CONFFILE has been modified by you." + echo "Saving as $CONFFILE.dpkg-bak ..." + mv -f "$CONFFILE" "$CONFFILE".dpkg-bak + else + echo "Removing obsolete conffile $CONFFILE ..." + rm -f "$CONFFILE" + fi +} + if [ "$1" = install ] || [ "$1" = upgrade ]; then if [ -e "/etc/udev/rules.d/85-hwclock.rules" ]; then if [ "`md5sum \"/etc/udev/rules.d/85-hwclock.rules\" | sed -e \"s/ .*//\"`" = \ @@ -10,6 +30,11 @@ if [ "$1" = install ] || [ "$1" = upgrade ]; then rm -f "/etc/udev/rules.d/85-hwclock.rules" fi fi + + if dpkg --compare-versions "$2" lt "2.20.1-2"; then + rm_conffile util-linux "/etc/init.d/hwclockfirst.sh" + fi + update-rc.d hwclockfirst.sh remove >/dev/null fi #DEBHELPER# -- 1.7.9

