Andreas and Chris, Thanks for your input.
On Tue, Aug 22, 2023 at 12:55:41PM +0200, Andreas Henriksson wrote: > HEADS UP: One thought here is that the init script will still need the > actual hwclock binary. While util-linux-extra currently is > pseudo-essential I think zeha plans to make it a regular package at some > point in the future which probably mean you want initscripts to depend > on it (or make the scripts handle that hwclock binary is not available, > but that sounds less compelling to me). You might want to add the > dependency now so that it's not forgotten once util-linux-extra is no > longer pseudo-essential. Dependency added. > (I'd be happy if I could see the actual diff, but could not spot a > relevant branch on salsa/debian/sysvinit.) I have just pushed wip/hwclock_takeover. The diff is also attached. (I am aware that the initscripts packaging doesn't make use of many recent debhelper conveniences. However, I am reluctant to make changes to that at the same time as handling this sort of transition). > Feel free to push a branch to salsa.debian.org/debian/util-linux with > proposed changes if you do prepare them. I have pushed branch leepen/hwclock_initscripts_migration for review and comment. > > If util-linux-extra were to use it, my understanding is that rm_conffile > > only > > removes *unmodified* conffiles so user modifications should be preserved. Testing this has been contrary to my expectation so far: both rm_conffile and remove-on-upgrade only preserve user modifications to conffiles only to the extent that they are renamed with either .dpkg-bak or .dpkg-old appended. However, that doesn't facilitate those modifications being preserved in the new initscript-owned conffile. Therefore, I think any active removal of these conffiles as obsolete in util-linux-extra should wait until Forky+1, by which time we can be sure that initscripts will have inherited the conffiles. Are you OK with that? Or do either of you have a better solution? > PS. I'd be happy to discuss potential improvements that can be done, but > think the first step should only be to get the files moved over. One > step at a time. Just don't want to leave you with the impression that > I/we are just dumping all the burden on you for old sins. For example > the hwclock(5) manpage probably contains questionable information. Thanks. As you say, for the future... Best wishes Mark
diff --git a/debian/control b/debian/control index e3b9c91c..fca27272 100644 --- a/debian/control +++ b/debian/control @@ -99,7 +99,10 @@ Multi-Arch: foreign Depends: sysvinit-utils (>= 3.05-1), sysv-rc | file-rc | openrc, + util-linux-extra, ${misc:Depends}, +Breaks: util-linux-extra (<< 2.39.2-1.1~) +Replaces: util-linux-extra (<< 2.39.2-1.1~) Recommends: e2fsprogs, psmisc, diff --git a/debian/initscripts.postinst b/debian/initscripts.postinst index 32c0afb0..bf841c82 100755 --- a/debian/initscripts.postinst +++ b/debian/initscripts.postinst @@ -24,7 +24,7 @@ INITSCRIPTS="mountkernfs.sh mount-configfs brightness hostname.sh mountdevsubfs. checkroot-bootclean.sh checkfs.sh mountall.sh mountall-bootclean.sh \ mountnfs.sh mountnfs-bootclean.sh bootmisc.sh urandom halt reboot \ umountroot umountfs umountnfs.sh sendsigs killprocs single motd \ - bootlogs rc.local rmnologin" + bootlogs rc.local rmnologin hwclock.sh" for F in $INITSCRIPTS; do if [ -x /etc/init.d/$F ]; then diff --git a/debian/initscripts.postrm b/debian/initscripts.postrm index 5e232568..ac314bed 100755 --- a/debian/initscripts.postrm +++ b/debian/initscripts.postrm @@ -9,7 +9,7 @@ INITSCRIPTS="mountkernfs.sh mount-configfs brightness hostname.sh mountdevsubfs. checkroot-bootclean.sh checkfs.sh mountall.sh mountall-bootclean.sh \ mountnfs.sh mountnfs-bootclean.sh bootmisc.sh urandom halt reboot \ umountroot umountfs umountnfs.sh sendsigs killprocs single motd \ - bootlogs rc.local rmnologin" + bootlogs rc.local rmnologin hwclock.sh" case "$1" in purge) diff --git a/debian/src/initscripts/Makefile b/debian/src/initscripts/Makefile index b13eafa3..db50873c 100644 --- a/debian/src/initscripts/Makefile +++ b/debian/src/initscripts/Makefile @@ -34,6 +34,9 @@ install: $(INSTALL) -d $(DESTDIR)$(sbindir)/. $(INSTALL) sbin/fsck.nfs $(DESTDIR)$(sbindir)/fsck.nfs + $(INSTALL) -Dt $(DESTDIR)/usr/lib/udev/rules.d usr/lib/udev/rules.d/hwclock.rules + $(INSTALL) usr/lib/udev/hwclock-set $(DESTDIR)/usr/lib/udev/hwclock-set + $(INSTALL) -d $(DESTDIR)/usr/share/man/man8 $(INSTALL_DATA) man/fsck.nfs.8 \ $(DESTDIR)/usr/share/man/man8/fsck.nfs.8 diff --git a/debian/src/initscripts/etc/default/hwclock b/debian/src/initscripts/etc/default/hwclock new file mode 100644 index 00000000..44b04312 --- /dev/null +++ b/debian/src/initscripts/etc/default/hwclock @@ -0,0 +1,2 @@ +# Settings for the hwclock init script. +# See hwclock(5) for supported settings. diff --git a/debian/src/initscripts/etc/init.d/hwclock.sh b/debian/src/initscripts/etc/init.d/hwclock.sh new file mode 100644 index 00000000..a9872b64 --- /dev/null +++ b/debian/src/initscripts/etc/init.d/hwclock.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: hwclock +# Required-Start: +# Required-Stop: mountdevsubfs +# Should-Stop: umountfs +# Default-Start: S +# Default-Stop: 0 6 +# Short-Description: Save system clock to hardware on shutdown. +### END INIT INFO + +# Note: this init script and related code is only useful if you +# run a sysvinit system, without NTP synchronization. + +if [ -e /run/systemd/system ] ; then + exit 0 +fi + +unset TZ + +hwclocksh() +{ + HCTOSYS_DEVICE=rtc0 + [ ! -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 "$@"; } + + case "$1" in + start) + # start is handled by /usr/lib/udev/rules.d/85-hwclock.rules. + return 0 + ;; + stop|restart|reload|force-reload) + # Updates the Hardware Clock with the System Clock time. + # This will *override* any changes made to the Hardware Clock, + # for example by the Linux kernel when NTP is in use. + log_action_msg "Saving the system clock to /dev/$HCTOSYS_DEVICE" + if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --systohc; then + verbose_log_action_msg "Hardware Clock updated to `date`" + fi + ;; + show) + /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --show + ;; + *) + log_success_msg "Usage: hwclock.sh {stop|reload|force-reload|show}" + log_success_msg " stop and reload set hardware (RTC) clock from kernel (system) clock" + return 1 + ;; + esac +} + +hwclocksh "$@" diff --git a/debian/src/initscripts/man/hwclock.5 b/debian/src/initscripts/man/hwclock.5 new file mode 100644 index 00000000..59d3d4a7 --- /dev/null +++ b/debian/src/initscripts/man/hwclock.5 @@ -0,0 +1,34 @@ +.TH HWCLOCK 5 "Dec 2020" "" "Debian Administrator's Manual" +.SH NAME +hwclock \- settings that affect the behaviour of the hwclock init script +.SH DESCRIPTION +The +.I /etc/default/hwclock +file contains settings in POSIX format: +.IP "" .5i +VAR=VAL +.PP +Only one assignment is allowed per line. +Comments (starting with '#') are also allowed. + +.SH SETTINGS +The following settings can be set. + +.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. + +If you change this, you also need to install a custom udev rule, +mirroring \fB/usr/lib/udev/rules.d/85-hwclock.rules\fP. Otherwise, +the hardware clock device will be ignored during boot. + +On almost all systems, this should not be changed. + +.SH NOTES + +On systems using systemd as init, the hwclock init script is ignored. + +.SH SEE ALSO +.BR hwclock (8), +.BR systemd-timesyncd.service (8) diff --git a/debian/src/initscripts/usr/lib/udev/hwclock-set b/debian/src/initscripts/usr/lib/udev/hwclock-set new file mode 100755 index 00000000..fec65edd --- /dev/null +++ b/debian/src/initscripts/usr/lib/udev/hwclock-set @@ -0,0 +1,12 @@ +#!/bin/sh +# Reset the System Clock to UTC if the hardware clock from which it +# was copied by the kernel was in localtime. + +dev=$1 + +if [ -e /run/systemd/system ] ; then + exit 0 +fi + +/sbin/hwclock --rtc=$dev --systz +/sbin/hwclock --rtc=$dev --hctosys diff --git a/debian/src/initscripts/usr/lib/udev/rules.d/hwclock.rules b/debian/src/initscripts/usr/lib/udev/rules.d/hwclock.rules new file mode 100644 index 00000000..c4c0b174 --- /dev/null +++ b/debian/src/initscripts/usr/lib/udev/rules.d/hwclock.rules @@ -0,0 +1,4 @@ +# Set the System Time from the Hardware Clock and set the kernel's timezone +# value to the local timezone when the kernel clock module is loaded. + +KERNEL=="rtc0", RUN+="/usr/lib/udev/hwclock-set $root/$name"