Package: dpkg Version: 1.18.3 Severity: serious Hi Guillem,
dpkg does not always properly pass the old version number when
calling "postinst configure" on package upgrades, sometimes there
is either no or an empty argument.
I have two cases where an 'apt-get dist-upgrade' from jessie to
stretch calls 'systemd.postinst configure' differently:
* a minimal jessie chroot (incorrect behavior)
* a minimal jessie chroot + bash-completion (correct behavior)
I noticed this while analyzing some strange piuparts failures in jessie
to stretch upgrades. Unfortunately I neglected it for a long time since
I assumed to have hit a strange bug in some systemd support scripts:
1m41.2s ERROR: FAIL: After purging files have disappeared:
/etc/dbus-1/system.d/org.freedesktop.machine1.conf.dpkg-remove not
owned
/etc/systemd/system/halt.target.wants/ not owned
/etc/systemd/system/halt.target.wants/hwclock-save.service ->
/lib/systemd/system/hwclock-save.service not owned
/etc/systemd/system/poweroff.target.wants/ not owned
/etc/systemd/system/poweroff.target.wants/hwclock-save.service ->
/lib/systemd/system/hwclock-save.service not owned
/etc/systemd/system/reboot.target.wants/ not owned
/etc/systemd/system/reboot.target.wants/hwclock-save.service ->
/lib/systemd/system/hwclock-save.service not owned
Digging into this I found the systemd.postinst from stretch performing
cleanup of hwclock-save.service and removal of that obsolete conffile
- but strangely only sometimes:
....
# Cleanup hwclock-save.service, which was shipped in jessie.
if dpkg --compare-versions "$2" lt-nl "219-8"; then
for t in reboot halt poweroff ; do
rm -fv /etc/systemd/system/${t}.target.wants/hwclock-save.service
rmdir --ignore-fail-on-non-empty /etc/systemd/system/${t}.target.wants
2> /dev/null || true
done
fi
....
#DEBHELPER#
(the #DEBHELPER# part gets several dkpm-maintscript-helper rm_conffile calls)
not here, which is wrong:
....
(Reading database ... 7446 files and directories currently installed.)
Preparing to unpack .../systemd_226-3_amd64.deb ...
Unpacking systemd (226-3) over (215-17+deb8u2) ...
Setting up util-linux (2.27-3) ...
Setting up systemd (226-3) ...
Installing new version of config file
/etc/dbus-1/system.d/org.freedesktop.login1.conf ...
Installing new version of config file
/etc/dbus-1/system.d/org.freedesktop.systemd1.conf ...
Installing new version of config file /etc/pam.d/systemd-user ...
Installing new version of config file /etc/systemd/bootchart.conf ...
Installing new version of config file /etc/systemd/journald.conf ...
Installing new version of config file /etc/systemd/logind.conf ...
Installing new version of config file /etc/systemd/resolved.conf ...
Installing new version of config file /etc/systemd/system.conf ...
Installing new version of config file /etc/systemd/timesyncd.conf ...
Installing new version of config file /etc/systemd/user.conf ...
Created symlink from
/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service to
/lib/systemd/system/systemd-timesyncd.service.
addgroup: The group `systemd-journal' already exists as a system group.
Exiting.
(Reading database ...
....
but here, which is correct:
....
(Reading database ... 8034 files and directories currently installed.)
Preparing to unpack .../systemd_226-3_amd64.deb ...
Unpacking systemd (226-3) over (215-17+deb8u2) ...
Setting up util-linux (2.27-3) ...
Setting up systemd (226-3) ...
Installing new version of config file
/etc/dbus-1/system.d/org.freedesktop.login1.conf ...
Installing new version of config file
/etc/dbus-1/system.d/org.freedesktop.systemd1.conf ...
Installing new version of config file /etc/pam.d/systemd-user ...
Installing new version of config file /etc/systemd/bootchart.conf ...
Installing new version of config file /etc/systemd/journald.conf ...
Installing new version of config file /etc/systemd/logind.conf ...
Installing new version of config file /etc/systemd/resolved.conf ...
Installing new version of config file /etc/systemd/system.conf ...
Installing new version of config file /etc/systemd/timesyncd.conf ...
Installing new version of config file /etc/systemd/user.conf ...
Created symlink from
/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service to
/lib/systemd/system/systemd-timesyncd.service.
addgroup: The group `systemd-journal' already exists as a system group.
Exiting.
Removing obsolete conffile /etc/dbus-1/system.d/org.freedesktop.machine1.conf
...
(Reading database ...
....
So I rebuilt systemd with more debug output in the postinst script to see the
following:
....
(Reading database ... 7446 files and directories currently installed.)
Preparing to unpack ..././systemd_226-4.1_amd64.deb ...
Unpacking systemd (226-4.1) over (215-17+deb8u2) ...
Setting up util-linux (2.27-3) ...
Setting up systemd (226-4.1) ...
Installing new version of config file
/etc/dbus-1/system.d/org.freedesktop.login1.conf ...
Installing new version of config file
/etc/dbus-1/system.d/org.freedesktop.systemd1.conf ...
Installing new version of config file /etc/pam.d/systemd-user ...
Installing new version of config file /etc/systemd/bootchart.conf ...
Installing new version of config file /etc/systemd/journald.conf ...
Installing new version of config file /etc/systemd/logind.conf ...
Installing new version of config file /etc/systemd/resolved.conf ...
Installing new version of config file /etc/systemd/system.conf ...
Installing new version of config file /etc/systemd/timesyncd.conf ...
Installing new version of config file /etc/systemd/user.conf ...
+ echo ** this is /var/lib/dpkg/info/systemd.postinst configure
** this is /var/lib/dpkg/info/systemd.postinst configure
+ set -e
+ [ configure = triggered ]
+ dpkg --compare-versions lt 214-1
+ systemctl enable [email protected]
+ systemctl enable remote-fs.target
+ dpkg --compare-versions lt 218-11~
+ systemctl enable systemd-timesyncd.service
Created symlink from
/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service to
/lib/systemd/system/systemd-timesyncd.service.
+ dpkg --compare-versions lt 33-1
+ [ -f /etc/default/rcS ]
+ . /etc/default/rcS
....
+ dpkg --compare-versions ge 204
+ [ -n ]
+ dpkg --compare-versions lt-nl 219-8
+ echo NO hwclock-save.service cleanup ()
NO hwclock-save.service cleanup ()
+ _systemctl is-active --quiet resolvconf
+ [ -d /run/systemd/system ]
+ _systemctl start systemd-networkd-resolvconf-update.path
+ [ -d /run/systemd/system ]
+ [ -d /run/systemd/system ]
+ dpkg-maintscript-helper rm_conffile
/etc/bash_completion.d/systemctl-bash-completion.sh 204-1~ systemd -- configure
+ dpkg-maintscript-helper rm_conffile
/etc/bash_completion.d/systemd-bash-completion.sh 204-1~ systemd -- configure
+ dpkg-maintscript-helper mv_conffile /etc/systemd/systemd-logind.conf
/etc/systemd/logind.conf 204-1~ systemd -- configure
+ dpkg-maintscript-helper mv_conffile /etc/systemd/systemd-journald.conf
/etc/systemd/journald.conf 204-1~ systemd -- configure
+ dpkg-maintscript-helper rm_conffile
/etc/dbus-1/system.d/org.freedesktop.machine1.conf 224-2~ systemd -- configure
(Reading database ...
....
So the postinst script is called without a "$2" parameter of "215-17+deb8u2"
causing several postinst actions to be skipped. It may be that there is an
empty string being passed instead, since 'echo "** this is $0 $@"' emitted
a trailing space:
"** this is /var/lib/dpkg/info/systemd.postinst configure "
And this is the output in the case where it is correct:
....
(Reading database ... 8034 files and directories currently installed.)
Preparing to unpack ..././systemd_226-4.1_amd64.deb ...
Unpacking systemd (226-4.1) over (215-17+deb8u2) ...
Setting up util-linux (2.27-3) ...
Setting up systemd (226-4.1) ...
Installing new version of config file
/etc/dbus-1/system.d/org.freedesktop.login1.conf ...
Installing new version of config file
/etc/dbus-1/system.d/org.freedesktop.systemd1.conf ...
Installing new version of config file /etc/pam.d/systemd-user ...
Installing new version of config file /etc/systemd/bootchart.conf ...
Installing new version of config file /etc/systemd/journald.conf ...
Installing new version of config file /etc/systemd/logind.conf ...
Installing new version of config file /etc/systemd/resolved.conf ...
Installing new version of config file /etc/systemd/system.conf ...
Installing new version of config file /etc/systemd/timesyncd.conf ...
Installing new version of config file /etc/systemd/user.conf ...
+ echo ** this is /var/lib/dpkg/info/systemd.postinst configure 215-17+deb8u2
** this is /var/lib/dpkg/info/systemd.postinst configure 215-17+deb8u2
+ set -e
+ [ configure = triggered ]
+ dpkg --compare-versions 215-17+deb8u2 lt 214-1
+ dpkg --compare-versions 215-17+deb8u2 lt 218-11~
+ systemctl enable systemd-timesyncd.service
Created symlink from
/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service to
/lib/systemd/system/systemd-timesyncd.service.
+ dpkg --compare-versions 215-17+deb8u2 lt 33-1
....
+ [ -n 215-17+deb8u2 ]
+ _systemctl daemon-reexec
+ [ -d /run/systemd/system ]
+ _systemctl try-restart systemd-networkd.service
+ [ -d /run/systemd/system ]
+ _systemctl try-restart systemd-resolved.service
+ [ -d /run/systemd/system ]
+ _systemctl try-restart systemd-timesyncd.service
+ [ -d /run/systemd/system ]
+ dpkg --compare-versions 215-17+deb8u2 lt-nl 219-8
+ echo cleanup hwclock-save.service
cleanup hwclock-save.service
+ rm -fv /etc/systemd/system/reboot.target.wants/hwclock-save.service
removed '/etc/systemd/system/reboot.target.wants/hwclock-save.service'
+ rmdir --ignore-fail-on-non-empty /etc/systemd/system/reboot.target.wants
+ rm -fv /etc/systemd/system/halt.target.wants/hwclock-save.service
removed '/etc/systemd/system/halt.target.wants/hwclock-save.service'
+ rmdir --ignore-fail-on-non-empty /etc/systemd/system/halt.target.wants
+ rm -fv /etc/systemd/system/poweroff.target.wants/hwclock-save.service
removed '/etc/systemd/system/poweroff.target.wants/hwclock-save.service'
+ rmdir --ignore-fail-on-non-empty /etc/systemd/system/poweroff.target.wants
+ _systemctl is-active --quiet resolvconf
+ [ -d /run/systemd/system ]
+ _systemctl start systemd-networkd-resolvconf-update.path
+ [ -d /run/systemd/system ]
+ [ -d /run/systemd/system ]
+ dpkg-maintscript-helper rm_conffile
/etc/bash_completion.d/systemctl-bash-completion.sh 204-1~ systemd -- configure
215-17+deb8u2
+ dpkg-maintscript-helper rm_conffile
/etc/bash_completion.d/systemd-bash-completion.sh 204-1~ systemd -- configure
215-17+deb8u2
+ dpkg-maintscript-helper mv_conffile /etc/systemd/systemd-logind.conf
/etc/systemd/logind.conf 204-1~ systemd -- configure 215-17+deb8u2
+ dpkg-maintscript-helper mv_conffile /etc/systemd/systemd-journald.conf
/etc/systemd/journald.conf 204-1~ systemd -- configure 215-17+deb8u2
+ dpkg-maintscript-helper rm_conffile
/etc/dbus-1/system.d/org.freedesktop.machine1.conf 224-2~ systemd -- configure
215-17+deb8u2
Removing obsolete conffile /etc/dbus-1/system.d/org.freedesktop.machine1.conf
...
(Reading database ...
So in these two cases completely different codepaths in the postinst are taken.
I don't know about other packages, since this is (so far) the only one leaving
a visible trace from this mistreatment in piuparts. (Well, there are several
other systemd symlink related problems that nobody managed to debug so far.)
Attached are two logs where I did this upgrade test with piuparts, but
it should be quite easy to reproduce it manually.
Andreas
bad.log.gz
Description: application/gzip
good.log.gz
Description: application/gzip

