[arch-projects] [PATCH] Make hwclock --adjust as well as --systohc optional (FS#13684)
This turns all hardware clock write access (setting and adjusting) the into an optional daemon. (FS#13684) Should fix issues when using ntpd (kernel 11-minute-mode) and also in case of dual-boot. Further more the out of box HARDWARECLOCK setting is changed to "UTC" and "localtime" is discouraged because it can really mess up things especially with 'hwclock --adjust'. For previous discussion see https://bugs.archlinux.org/task/13684 From 39d86d1d831210aca9f592eed5555389b2216d7c Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> Date: Mon, 28 Mar 2011 15:01:43 +0200 Subject: [PATCH] Make hwclock --adjust as well as --systohc optional (FS#13684) --- adjtime.cron | 2 +- hwclock | 39 +++++++++++++++++++++++++++++++++++++++ install.sh | 2 +- rc.conf | 8 ++++++-- rc.shutdown | 13 ++----------- rc.sysinit | 27 +++------------------------ 6 files changed, 52 insertions(+), 39 deletions(-) create mode 100644 hwclock diff --git a/adjtime.cron b/adjtime.cron index a876506..7691aa5 100755 --- a/adjtime.cron +++ b/adjtime.cron @@ -10,6 +10,6 @@ case $HARDWARECLOCK in *) HWCLOCK_PARAMS="";; esac -if [[ $HWCLOCK_PARAMS ]]; then +if [[ $HWCLOCK_PARAMS && -f /var/daemons/hwclock ]]; then /sbin/hwclock $HWCLOCK_PARAMS fi diff --git a/hwclock b/hwclock new file mode 100644 index 0000000..d584276 --- /dev/null +++ b/hwclock @@ -0,0 +1,39 @@ +#!/bin/bash + +. /etc/rc.conf +. /etc/rc.d/functions + +case $HARDWARECLOCK in + UTC) HWCLOCK_PARAMS="--utc";; + localtime) HWCLOCK_PARAMS="--localtime";; + *) HWCLOCK_PARAMS="";; +esac + +case "$1" in + start) + if [[ $HWCLOCK_PARAMS ]]; then + status "Adjusting Hardware Clock" \ + /sbin/hwclock --adjust + stat_busy "Setting System Clock" + /sbin/hwclock --hctosys $HWCLOCK_PARAMS || stat_die + stat_done + # Note: This also enables /etc/cron.hourly/adjtime + add_daemon clock + fi + ;; + stop) + if [[ $HWCLOCK_PARAMS ]]; then + stat_busy "Saving System Clock" + /sbin/hwclock --systohc $HWCLOCK_PARAMS || stat_die + stat_done + fi + rm_daemon clock + ;; + restart) + $0 stop + sleep 1 + $0 start + ;; + *) + echo "usage: $0 {start|stop|restart}" +esac diff --git a/install.sh b/install.sh index 2b2cbbc..8e6c3d7 100755 --- a/install.sh +++ b/install.sh @@ -15,7 +15,7 @@ done install -D -m755 adjtime.cron ${DESTDIR}/etc/cron.hourly/adjtime install -D -m644 functions ${DESTDIR}/etc/rc.d/functions || exit 1 -for i in network netfs; do +for i in hwclock network netfs; do install -D -m755 $i ${DESTDIR}/etc/rc.d/$i || exit 1 done diff --git a/rc.conf b/rc.conf index d2b0517..02bb1d7 100644 --- a/rc.conf +++ b/rc.conf @@ -11,6 +11,7 @@ # process. If set to 'no', the C locale will be used. # HARDWARECLOCK: set to "UTC" or "localtime", any other value will result # in the hardware clock being left untouched (useful for virtualization) +# Note: Using "localtime" is discouraged. # TIMEZONE: timezones are found in /usr/share/zoneinfo # KEYMAP: keymaps are found in /usr/share/kbd/keymaps # CONSOLEFONT: found in /usr/share/kbd/consolefonts (only needed for non-US) @@ -19,7 +20,7 @@ # LOCALE="en_US.UTF-8" DAEMON_LOCALE="no" -HARDWARECLOCK="localtime" +HARDWARECLOCK="UTC" TIMEZONE="Canada/Pacific" KEYMAP="us" CONSOLEFONT= @@ -105,4 +106,7 @@ NETWORK_PERSIST="no" # - prefix a daemon with a ! to disable it # - prefix a daemon with a @ to start it up in the background # -DAEMONS=(syslog-ng network netfs crond) +# If something other takes care of your hardware clock (ntpd, dual-boot...) +# you should disable 'hwclock' here. +# +DAEMONS=(hwclock syslog-ng network netfs crond) diff --git a/rc.shutdown b/rc.shutdown index 0acca49..fef1117 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -35,21 +35,12 @@ fi /bin/dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &> /dev/null stat_done -stat_busy "Saving System Clock" if [[ $TIMEZONE && -e /usr/share/zoneinfo/$TIMEZONE ]]; then /bin/rm -f /etc/localtime - /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime + status "Saving Time Zone" \ + /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime fi -HWCLOCK_PARAMS="--systohc" -case $HARDWARECLOCK in - UTC) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc";; - localtime) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime";; - *) HWCLOCK_PARAMS="";; -esac -[[ $HWCLOCK_PARAMS ]] && /sbin/hwclock $HWCLOCK_PARAMS -stat_done - # removing psmouse module to fix some reboot issues on newer laptops /sbin/modprobe -r psmouse >/dev/null 2>&1 diff --git a/rc.sysinit b/rc.sysinit index 9797611..e949180 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -66,7 +66,7 @@ if [[ $HWCLOCK_PARAMS ]]; then # configured timezone. Any new timezone put in rc.conf is copied over at # a later time. # This does *NOT* take into account a time adjustment file as /var may not be - # mounted yet. A second set occurs later to match rc.conf. + # mounted yet. A second set may occur in rc.d/hwclock to match rc.conf. if [[ -f /etc/localtime ]]; then /sbin/hwclock $HWCLOCK_PARAMS --noadjfile fi @@ -304,28 +304,12 @@ status "Retrying failed UDev events" /sbin/udevadm trigger --action=add --type=f status "Activating Swap" /sbin/swapon -a -stat_busy "Configuring System Clock" if [[ $TIMEZONE && -e /usr/share/zoneinfo/$TIMEZONE ]]; then /bin/rm -f /etc/localtime - /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime + status "Configuring Time Zone" \ + /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime fi -clock_pid="" -if [[ $HWCLOCK_PARAMS ]]; then - # This time, we set the clock for real. Use the adjustment file now that - # /var will definitely be available, and then set the system clock once - # the hardware clock has been adjusted accordingly. The backgrounding magic - # is due to the fact that the second call to hwclock will almost always - # take ~1 second because of the clock granularity, and we might as well - # stay busy. - ( - /sbin/hwclock --adjust - /sbin/hwclock $HWCLOCK_PARAMS - ) & - clock_pid=$! -fi -stat_done - RANDOM_SEED=/var/lib/misc/random-seed if [[ -f $RANDOM_SEED ]]; then stat_busy "Initializing Random Seed" @@ -398,11 +382,6 @@ set_consolefont /bin/dmesg >| /var/log/dmesg.log -# final hwclock setting needs to be done at this point -if [[ $clock_pid ]]; then - wait $clock_pid -fi - run_hook sysinit_end # End of file -- 1.7.0.3
On Mon, Mar 28, 2011 at 03:34:22PM +0200, Kurt J. Bosch wrote:
This turns all hardware clock write access (setting and adjusting) the into an optional daemon. (FS#13684) Should fix issues when using ntpd (kernel 11-minute-mode) and also in case of dual-boot. Further more the out of box HARDWARECLOCK setting is changed to "UTC" and "localtime" is discouraged because it can really mess up things especially with 'hwclock --adjust'.
For previous discussion see https://bugs.archlinux.org/task/13684
From 39d86d1d831210aca9f592eed5555389b2216d7c Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> Date: Mon, 28 Mar 2011 15:01:43 +0200 Subject: [PATCH] Make hwclock --adjust as well as --systohc optional (FS#13684)
--- adjtime.cron | 2 +- hwclock | 39 +++++++++++++++++++++++++++++++++++++++ install.sh | 2 +- rc.conf | 8 ++++++-- rc.shutdown | 13 ++----------- rc.sysinit | 27 +++------------------------ 6 files changed, 52 insertions(+), 39 deletions(-) create mode 100644 hwclock
diff --git a/adjtime.cron b/adjtime.cron index a876506..7691aa5 100755 --- a/adjtime.cron +++ b/adjtime.cron @@ -10,6 +10,6 @@ case $HARDWARECLOCK in *) HWCLOCK_PARAMS="";; esac
-if [[ $HWCLOCK_PARAMS ]]; then +if [[ $HWCLOCK_PARAMS && -f /var/daemons/hwclock ]]; then
Think you meant /var/run/daemons/hwclock here.
/sbin/hwclock $HWCLOCK_PARAMS fi diff --git a/hwclock b/hwclock new file mode 100644 index 0000000..d584276 --- /dev/null +++ b/hwclock @@ -0,0 +1,39 @@ +#!/bin/bash + +. /etc/rc.conf +. /etc/rc.d/functions + +case $HARDWARECLOCK in + UTC) HWCLOCK_PARAMS="--utc";; + localtime) HWCLOCK_PARAMS="--localtime";; + *) HWCLOCK_PARAMS="";; +esac + +case "$1" in + start) + if [[ $HWCLOCK_PARAMS ]]; then + status "Adjusting Hardware Clock" \ + /sbin/hwclock --adjust + stat_busy "Setting System Clock" + /sbin/hwclock --hctosys $HWCLOCK_PARAMS || stat_die + stat_done + # Note: This also enables /etc/cron.hourly/adjtime + add_daemon clock
And you probably meant add_daemon hwclock here.
+ fi + ;; + stop) + if [[ $HWCLOCK_PARAMS ]]; then + stat_busy "Saving System Clock" + /sbin/hwclock --systohc $HWCLOCK_PARAMS || stat_die + stat_done + fi + rm_daemon clock + ;; + restart) + $0 stop + sleep 1 + $0 start + ;; + *) + echo "usage: $0 {start|stop|restart}" +esac diff --git a/install.sh b/install.sh index 2b2cbbc..8e6c3d7 100755 --- a/install.sh +++ b/install.sh @@ -15,7 +15,7 @@ done install -D -m755 adjtime.cron ${DESTDIR}/etc/cron.hourly/adjtime
install -D -m644 functions ${DESTDIR}/etc/rc.d/functions || exit 1 -for i in network netfs; do +for i in hwclock network netfs; do install -D -m755 $i ${DESTDIR}/etc/rc.d/$i || exit 1 done
diff --git a/rc.conf b/rc.conf index d2b0517..02bb1d7 100644 --- a/rc.conf +++ b/rc.conf @@ -11,6 +11,7 @@ # process. If set to 'no', the C locale will be used. # HARDWARECLOCK: set to "UTC" or "localtime", any other value will result # in the hardware clock being left untouched (useful for virtualization) +# Note: Using "localtime" is discouraged. # TIMEZONE: timezones are found in /usr/share/zoneinfo # KEYMAP: keymaps are found in /usr/share/kbd/keymaps # CONSOLEFONT: found in /usr/share/kbd/consolefonts (only needed for non-US) @@ -19,7 +20,7 @@ # LOCALE="en_US.UTF-8" DAEMON_LOCALE="no" -HARDWARECLOCK="localtime" +HARDWARECLOCK="UTC" TIMEZONE="Canada/Pacific" KEYMAP="us" CONSOLEFONT= @@ -105,4 +106,7 @@ NETWORK_PERSIST="no" # - prefix a daemon with a ! to disable it # - prefix a daemon with a @ to start it up in the background # -DAEMONS=(syslog-ng network netfs crond) +# If something other takes care of your hardware clock (ntpd, dual-boot...) +# you should disable 'hwclock' here. +# +DAEMONS=(hwclock syslog-ng network netfs crond) diff --git a/rc.shutdown b/rc.shutdown index 0acca49..fef1117 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -35,21 +35,12 @@ fi /bin/dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &> /dev/null stat_done
-stat_busy "Saving System Clock" if [[ $TIMEZONE && -e /usr/share/zoneinfo/$TIMEZONE ]]; then /bin/rm -f /etc/localtime - /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime + status "Saving Time Zone" \ + /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
Where'd this come from?
fi
-HWCLOCK_PARAMS="--systohc" -case $HARDWARECLOCK in - UTC) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc";; - localtime) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime";; - *) HWCLOCK_PARAMS="";; -esac -[[ $HWCLOCK_PARAMS ]] && /sbin/hwclock $HWCLOCK_PARAMS -stat_done - # removing psmouse module to fix some reboot issues on newer laptops /sbin/modprobe -r psmouse >/dev/null 2>&1
diff --git a/rc.sysinit b/rc.sysinit index 9797611..e949180 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -66,7 +66,7 @@ if [[ $HWCLOCK_PARAMS ]]; then # configured timezone. Any new timezone put in rc.conf is copied over at # a later time. # This does *NOT* take into account a time adjustment file as /var may not be - # mounted yet. A second set occurs later to match rc.conf. + # mounted yet. A second set may occur in rc.d/hwclock to match rc.conf. if [[ -f /etc/localtime ]]; then /sbin/hwclock $HWCLOCK_PARAMS --noadjfile fi @@ -304,28 +304,12 @@ status "Retrying failed UDev events" /sbin/udevadm trigger --action=add --type=f
status "Activating Swap" /sbin/swapon -a
-stat_busy "Configuring System Clock" if [[ $TIMEZONE && -e /usr/share/zoneinfo/$TIMEZONE ]]; then /bin/rm -f /etc/localtime - /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime + status "Configuring Time Zone" \ + /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime fi
-clock_pid="" -if [[ $HWCLOCK_PARAMS ]]; then - # This time, we set the clock for real. Use the adjustment file now that - # /var will definitely be available, and then set the system clock once - # the hardware clock has been adjusted accordingly. The backgrounding magic - # is due to the fact that the second call to hwclock will almost always - # take ~1 second because of the clock granularity, and we might as well - # stay busy. - ( - /sbin/hwclock --adjust - /sbin/hwclock $HWCLOCK_PARAMS - ) & - clock_pid=$! -fi -stat_done - RANDOM_SEED=/var/lib/misc/random-seed if [[ -f $RANDOM_SEED ]]; then stat_busy "Initializing Random Seed" @@ -398,11 +382,6 @@ set_consolefont
/bin/dmesg >| /var/log/dmesg.log
-# final hwclock setting needs to be done at this point -if [[ $clock_pid ]]; then - wait $clock_pid -fi - run_hook sysinit_end
# End of file -- 1.7.0.3
This is an awful lot of movement for just one patch. I also don't agree with adding an extra daemon to take care of the hwclock when it could be satisfied just as easily by a simple var in /etc/rc.conf (falling back on the current behavior if it doesn't exist). dave
28.03.2011 16:20, Dave Reisner:
... This is an awful lot of movement for just one patch. I also don't agree with adding an extra daemon to take care of the hwclock when it could be satisfied just as easily by a simple var in /etc/rc.conf (falling back on the current behavior if it doesn't exist). Thank you for your comments. Actually the daemon idea came from Tom. Afaics the main benefits is you could use it in a pm-utils hook to fix hardware clock drift while suspended to disk.
-- Kurt
On Mon, Mar 28, 2011 at 04:52:16PM +0200, Kurt J. Bosch wrote:
28.03.2011 16:20, Dave Reisner:
... This is an awful lot of movement for just one patch. I also don't agree with adding an extra daemon to take care of the hwclock when it could be satisfied just as easily by a simple var in /etc/rc.conf (falling back on the current behavior if it doesn't exist). Thank you for your comments. Actually the daemon idea came from Tom. Afaics the main benefits is you could use it in a pm-utils hook to fix hardware clock drift while suspended to disk.
My hangup (which I should have mentioned in my previous email), is that the popular use case will always be to set the hwclock as we do right now. This changes default behavior without any fallback. The majority of users are inconvenienced and need to pick up on this change. I'll have to read up on pm-utils hooks to see if there's another approach that would also be suitable. dave
On Mon, Mar 28, 2011 at 5:02 PM, Dave Reisner <d@falconindy.com> wrote:
My hangup (which I should have mentioned in my previous email), is that the popular use case will always be to set the hwclock as we do right now. This changes default behavior without any fallback. The majority of users are inconvenienced and need to pick up on this change. I'll have to read up on pm-utils hooks to see if there's another approach that would also be suitable.
Thanks for the clarification Dave. I think you pinpoint the important issue. If you are right that enabling hwclock will be the common setup, then I agree with you. However, after discussing and thinking about this I think most people should NOT enable hwclock. These are the pros and cons of enabling hwclock: pro: relatively accurate system time even with no internet connection (but why should anyone care about accurate system time if they are not connected to other computers that they need to be in sync with? In that case, the only purpose of the systemtime is to work as a glorified wall clock.) con: if dual-boot, or ntpd is used hwclock will give a much less reliable time than the user might assume (ntpd+hwclock is worse than ntpd alone and worse than hwclock alone), and if localtime (so DST) is used we might get total havoc. In other words, the only people who should enable the hwclock daemon are the ones who need system time to be more accurate than a regular wall clock and who do not have a network connection so cannot use ntpd. I guess that leaves people who want to use their hwclock as a time source for an ntpd server on their local network where the local network is not connected to the internet, and where they do not have a proper time source. I guess that many people are in a situation where they really should not be stepping the hwclock without realising they are, so this change would fix some weird issues for them. For the (hopefully few) who genuinely need to use hwclock we'll have to write an announcement of course. Please let me know if anyone disagrees with my analysis, or if I have overlooked something important. If my assumption that using hwclock should be relatively rare, then I think it would make sense to move it into a daemon for three reasons: 1) simplifies rc.sysinit 2) in general I think anything that does not need to be in rc.sysinit should not be there (simpler the better) 3) given the choice, I'd rather we did not add more variables to rc.conf, as removing them again in the future is a hassle What do you think? Tom
From 3a282def059b0ef71bbf5bda9797f2b3462d541d Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> Date: Mon, 28 Mar 2011 16:37:59 +0200 Subject: [PATCH 2/2] Fix hwclock daemon code --- adjtime.cron | 2 +- hwclock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/adjtime.cron b/adjtime.cron index 7691aa5..dac8cea 100755 --- a/adjtime.cron +++ b/adjtime.cron @@ -10,6 +10,6 @@ case $HARDWARECLOCK in *) HWCLOCK_PARAMS="";; esac -if [[ $HWCLOCK_PARAMS && -f /var/daemons/hwclock ]]; then +if [[ $HWCLOCK_PARAMS && -f /var/run/daemons/hwclock ]]; then /sbin/hwclock $HWCLOCK_PARAMS fi diff --git a/hwclock b/hwclock index d584276..d9de9e1 100644 --- a/hwclock +++ b/hwclock @@ -18,7 +18,7 @@ case "$1" in /sbin/hwclock --hctosys $HWCLOCK_PARAMS || stat_die stat_done # Note: This also enables /etc/cron.hourly/adjtime - add_daemon clock + add_daemon hwclock fi ;; stop) @@ -27,7 +27,7 @@ case "$1" in /sbin/hwclock --systohc $HWCLOCK_PARAMS || stat_die stat_done fi - rm_daemon clock + rm_daemon hwclock ;; restart) $0 stop -- 1.7.0.3
On Mon, Mar 28, 2011 at 3:34 PM, Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> wrote:
This turns all hardware clock write access (setting and adjusting) the into an optional daemon. (FS#13684) Should fix issues when using ntpd (kernel 11-minute-mode) and also in case of dual-boot. Further more the out of box HARDWARECLOCK setting is changed to "UTC" and "localtime" is discouraged because it can really mess up things especially with 'hwclock --adjust'.
In addition to fixing up the things mentioned by Dave, I suggest you drop the change of the status message, and split the "UTC as standard" into a separate patch. Maybe mentioning that using localtime might cause "known, difficult to diagnose and unfixable bugs". In general this looks fine to me, but we should reach a consensus on the daemon v. var issue. It was my suggestion to use a daemon, but I don't feel strongly about this. I saw that Dave just posted a new mail so I'll reply to that with my reasons, as I think it is relevant. Cheers, Tom
participants (3)
-
Dave Reisner
-
Kurt J. Bosch
-
Tom Gundersen