Hi, I wrote the attached patch to migrate the hwclock part of util-linux to /run, as requested in bug #620787. The patch contains the following changes:
- Introduced a variable, HWCLOCK_ADJFILE, that holds the name of the hwclock adjust file. - Removed the -d /etc check. - Added --adjfile switch to all invocations of /sbin/hwclock. - Migrated /etc/adjtime to /run/adjtime - Replaced -d /dev/.udev check with -d /run/udev Regards -- Pieter
From 9e6a458e98e664dc43531d5a68b7e7eb4733cdbb Mon Sep 17 00:00:00 2001 From: Pieter du Preez <pdupr...@gmail.com> Date: Thu, 23 Feb 2012 16:22:46 +0100 Subject: [PATCH] hwclock: Migrate to the /run directory. This patch is intended to migrate the hwclock part of util-linux to /run, as requested in bug #620787. The patch contains the following changes: - Introduced a variable, HWCLOCK_ADJFILE, that holds the name of the hwclock adjust file. - Removed the -d /etc check. - Added --adjfile switch to all invocations of /sbin/hwclock. - Migrated /etc/adjtime to /run/adjtime - Replaced -d /dev/.udev check with -d /run/udev Signed-off-by: Pieter du Preez <pdupr...@gmail.com> --- debian/README.Debian.hwclock | 2 +- debian/hwclock.sh | 28 ++++++++++++++++------------ debian/util-linux.dirs | 1 + debian/util-linux.postrm | 2 +- debian/util-linux.preinst | 8 ++++++++ 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/debian/README.Debian.hwclock b/debian/README.Debian.hwclock index c8b840c..4635fc6 100644 --- a/debian/README.Debian.hwclock +++ b/debian/README.Debian.hwclock @@ -54,7 +54,7 @@ chrony, as well as your computer's System Setup BIOS program, and any other OS you have in your machine will change the clock. Also, if hwclock --adjust is used, one must make sure the drift file -(/etc/adjtime) is deleted every time the system clock is set to a very +(/run/adjtime) is deleted every time the system clock is set to a very different value (even if you're using hwclock itself to do it!), or the drift computation might become invalid and cause the hardware clock to be incorrectly set the next time hwclock --adjust is used. diff --git a/debian/hwclock.sh b/debian/hwclock.sh index 9f5f345..5694e43 100644 --- a/debian/hwclock.sh +++ b/debian/hwclock.sh @@ -34,6 +34,10 @@ HWCLOCKPARS= # probably match the CONFIG_RTC_HCTOSYS_DEVICE kernel config option. HCTOSYS_DEVICE=rtc0 +# Set the default adjust file name. /sbin/hwclock will be invoked +# with the --adjfile=$HWCLOCK_ADJFILE switch. +HWCLOCK_ADJFILE=/run/adjtime + hwclocksh() { [ ! -x /sbin/hwclock ] && return 0 @@ -67,15 +71,15 @@ hwclocksh() case "$1" in start) - if [ -d /dev/.udev ]; then + if [ -d /run/udev ]; then return 0 fi - if [ -w /etc ] && [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then - echo "0.0 0 0.0" > /etc/adjtime + if [ ! -f $HWCLOCK_ADJFILE ] && [ ! -e $HWCLOCK_ADJFILE ]; then + echo "0.0 0 0.0" 2>/dev/null > $HWCLOCK_ADJFILE || true fi - if [ ! -w /etc/adjtime ]; then + if [ ! -w $HWCLOCK_ADJFILE ]; then NOADJ="--noadjfile" else NOADJ="" @@ -88,21 +92,21 @@ hwclocksh() # # 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 + # hwclock --systohc, or you must delete $HWCLOCK_ADJFILE # 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 + # $HWCLOCK_ADJFILE 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 + #/sbin/hwclock --adjfile=$HWCLOCK_ADJFILE --rtc=/dev/$HCTOSYS_DEVICE --adjust $GMT $BADYEAR : fi @@ -112,7 +116,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. - if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --hctosys $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then + if /sbin/hwclock --adjfile=$HWCLOCK_ADJFILE --rtc=/dev/$HCTOSYS_DEVICE --hctosys $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then # Announce the local time. verbose_log_action_msg "System Clock set to: `date $UTC`" else @@ -130,7 +134,7 @@ hwclocksh() # WARNING: If you disable this, any changes to the system # clock will not be carried across reboots. # - if [ ! -w /etc/adjtime ]; then + if [ ! -w $HWCLOCK_ADJFILE ]; then NOADJ="--noadjfile" else NOADJ="" @@ -141,7 +145,7 @@ hwclocksh() if [ "$GMT" = "-u" ]; then GMT="--utc" fi - if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --systohc $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then + if /sbin/hwclock --adjfile=$HWCLOCK_ADJFILE --rtc=/dev/$HCTOSYS_DEVICE --systohc $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then verbose_log_action_msg "Hardware Clock updated to `date`" fi else @@ -149,14 +153,14 @@ hwclocksh() fi ;; show) - if [ ! -w /etc/adjtime ]; then + if [ ! -w $HWCLOCK_ADJFILE ]; then NOADJ="--noadjfile" else NOADJ="" fi if [ "$HWCLOCKACCESS" != no ]; then - /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --show $GMT $HWCLOCKPARS $BADYEAR $NOADJ + /sbin/hwclock --adjfile=$HWCLOCK_ADJFILE --rtc=/dev/$HCTOSYS_DEVICE --show $GMT $HWCLOCKPARS $BADYEAR $NOADJ fi ;; *) diff --git a/debian/util-linux.dirs b/debian/util-linux.dirs index 5bf2782..1a0b120 100644 --- a/debian/util-linux.dirs +++ b/debian/util-linux.dirs @@ -23,3 +23,4 @@ usr/share/lintian/overrides/ lib/ lib/udev/ lib/udev/rules.d/ +run/ diff --git a/debian/util-linux.postrm b/debian/util-linux.postrm index 21630b1..8e0b97f 100644 --- a/debian/util-linux.postrm +++ b/debian/util-linux.postrm @@ -8,7 +8,7 @@ case "$1" in purge) update-rc.d hwclock.sh remove >/dev/null || true update-rc.d hwclockfirst.sh remove >/dev/null || true - rm -f /etc/adjtime + rm -f /run/adjtime ;; *) ;; diff --git a/debian/util-linux.preinst b/debian/util-linux.preinst index a6a6527..77c93a9 100644 --- a/debian/util-linux.preinst +++ b/debian/util-linux.preinst @@ -10,6 +10,14 @@ if [ "$1" = install ] || [ "$1" = upgrade ]; then rm -f "/etc/udev/rules.d/85-hwclock.rules" fi fi + # The following should be removed once "wheezy" becomes a "stable" release. + # Migrate /etc/adjtime to /run/adjtime. + if [ -e "/etc/adjtime" ] && [ -d "/run" ]; then + if [! -e "/run/adjtime" ]; then + cp -a /etc/adjtime /run/ + fi + rm -f /etc/adjtime + fi fi #DEBHELPER# -- 1.7.9