Source: molly-guard Version: 0.8.4 Severity: serious Tags: patch Hi,
I'm saddened to tell you that despite having taken three iterations on molly-guard already, I've still gotten it wrong. I got reports for debian-installer-utils and live-build that things were broken and looked deeper. You may find the backstory at https://lists.debian.org/debian-devel/2025/01/msg00125.html. As a result, I sketched out all the possible upgrade scenarios for molly-guard (with three different init systems) and tested the full matrix with an unmodified rebuild of molly-guard. Sure enough it would quickly fail. Earlier, my understanding of the --rename semantics were wrong and as a result, it would wrongly rename files. A simple case to see this is starting with bookworm, the installing molly-guard from trixie and removing it. So I set out rewrite the preinst script avoiding --rename as much as possible and instead handling all of the renames manually. This may sound backwards, but it appears to practically work much better. At least the tests I wrote now pass. I really do appreciate reviews if you have cycles to spend on that. In the maintainer script, I've added more comments to make it easier to follow. In particular, reviewing the test cases and judging whether they cover all relevant scenarios would be very welcome. If that's asking too much, so be it. What I can say now is that the current state in unstable demonstrably has bugs and those bugs no longer reproduce when applying the attached patch. I really hope that this is my last molly-guard update before trixie. Keep the fingers crossed. Helmut
diff --minimal -Nru molly-guard-0.8.4/debian/changelog molly-guard-0.8.4+nmu1/debian/changelog --- molly-guard-0.8.4/debian/changelog 2024-03-09 22:38:43.000000000 +0100 +++ molly-guard-0.8.4+nmu1/debian/changelog 2025-01-14 12:40:30.000000000 +0100 @@ -1,3 +1,11 @@ +molly-guard (0.8.4+nmu1) UNRELEASED; urgency=medium + + * Non-maintainer upload. + * Rework the duplicated diversions to avoid trouble with --rename. + (DEP17, Closes: #-1) + + -- Helmut Grohne <hel...@subdivi.de> Tue, 14 Jan 2025 12:40:30 +0100 + molly-guard (0.8.4) unstable; urgency=medium [ Helmut Grohne ] diff --minimal -Nru molly-guard-0.8.4/debian/molly-guard.preinst molly-guard-0.8.4+nmu1/debian/molly-guard.preinst --- molly-guard-0.8.4/debian/molly-guard.preinst 2024-03-09 22:38:43.000000000 +0100 +++ molly-guard-0.8.4+nmu1/debian/molly-guard.preinst 2025-01-14 12:40:30.000000000 +0100 @@ -15,31 +15,30 @@ case "$1" in install|upgrade) for cmd in halt poweroff reboot shutdown coldreboot ; do - truenameusr="$(dpkg-divert --truename "/usr/sbin/$cmd")" - truenamealias="$(dpkg-divert --truename "/sbin/$cmd")" - rename_flag=--no-rename - if test "$truenameusr" = "/usr/sbin/$cmd" && test "$truenamealias" = "/sbin/$cmd"; then - rename_flag=--rename - fi - if test "$truenameusr" = "/usr/sbin/$cmd"; then - dpkg-divert --package molly-guard --divert "/usr/sbin/$cmd.no-molly-guard" "$rename_flag" --add "/usr/sbin/$cmd" - elif test "$truenameusr" != "/usr/sbin/$cmd.no-molly-guard"; then - dpkg-divert --package molly-guard --no-rename --remove "/usr/sbin/$cmd" - dpkg-divert --package molly-guard --no-rename --divert "/usr/sbin/$cmd.no-molly-guard" --add "/usr/sbin/$cmd" - if test -e "$truenameusr" || test -h "$truenameusr"; then - mv "$truenameusr" "/usr/sbin/$cmd.no-molly-guard" - fi - fi - if test "$truenamealias" = "/sbin/$cmd"; then - # DEP17 M18 duplicated diversion. Can be --removed after trixie. - dpkg-divert --package molly-guard --divert "/sbin/$cmd.no-molly-guard.usr-is-merged" "$rename_flag" --add "/sbin/$cmd" - elif test "$truenamealias" != "/sbin/$cmd.no-molly-guard.usr-is-merged"; then - dpkg-divert --package molly-guard --no-rename --remove "/sbin/$cmd" - dpkg-divert --package molly-guard --no-rename --divert "/sbin/$cmd.no-molly-guard.usr-is-merged" --add "/sbin/$cmd" - if test -e "$truenamealias" || test -h "$truenamealias"; then - mv "$truenamealias" "/sbin/$cmd.no-molly-guard.usr-is-merged" + # DEP17 M18 duplicated diversion. Once trixie is released, + # remove the aliased diversion in postinst and only have + # the canonical one with --rename here. + truename="$(dpkg-divert --truename "/sbin/$cmd")" + if test "$(dpkg-divert --truename "/usr/sbin/$cmd")" != "/usr/sbin/$cmd"; then + : # Canonically diverted already. Nothing to rename. + elif test "$truenam" = "/sbin/$cmd.no-molly-guard.usr-is-merged"; then + : # Aliased diversion as expected. Nothing to rename. + elif test "$truename" != "/sbin/$cmd"; then + # Aliased diversion with earlier target. Fix target. + dpkg-divert --remove --no-rename "/sbin/$cmd" + if test -e "$DPKG_ROOT$truename" -o -h "$DPKG_ROOT$truename"; then + mv "$DPKG_ROOT$truename" "$DPKG_ROOT/sbin/$cmd.no-molly-guard.usr-is-merged" fi + elif dpkg -S "/sbin/$cmd" >/dev/null 2>&1; then + # Not diverted yet. Installed as aliased. + mv "$DPKG_ROOT/sbin/$cmd" "$DPKG_ROOT/sbin/$cmd.no-molly-guard.usr-is-merged" + elif test -e "$DPKG_ROOT/usr/sbin/$cmd" -o -h "$DPKG_ROOT/usr/sbin/$cmd"; then + # Not diverted yet. Installed as canonical. + mv "$DPKG_ROOT/usr/sbin/$cmd" "$DPKG_ROOT/usr/sbin/$cmd.no-molly-guard" fi + # All necessary moving has been done. Hence --no-rename. + dpkg-divert --add --no-rename --divert "/sbin/$cmd.no-molly-guard.usr-is-merged" "/sbin/$cmd" + dpkg-divert --add --no-rename --divert "/usr/sbin/$cmd.no-molly-guard" "/usr/sbin/$cmd" done for cmd in pm-hibernate pm-suspend pm-suspend-hybrid ; do @@ -47,6 +46,7 @@ if test "$truename" = "/usr/sbin/$cmd"; then dpkg-divert --package molly-guard --divert "/usr/sbin/$cmd.no-molly-guard" --rename "/usr/sbin/$cmd" elif test "$truename" != "/usr/sbin/$cmd.no-molly-guard"; then + # Upgrading from pre-trixie. Update the diversion target from aliased to canonical. dpkg-divert --package molly-guard --no-rename --remove "/usr/sbin/$cmd" dpkg-divert --package molly-guard --divert "/usr/sbin/$cmd.no-molly-guard" --no-rename --add "/usr/sbin/$cmd" if test -e "$truename" -o -h "$truename"; then
test.sh
Description: Bourne shell script