Package: init-system-helpers Version: 1.23 Severity: normal Tags: patch Dear Maintainer,
if a package in version 1 had WantedBy=a.target and this is changed to WantedBy=b.target in version 2 of that package, deb-systemd-helper will properly create the links in b.target.wants/, but will not remove the links in a.target.wants/. Same goes with changes in Alias= and changes in Also=. I've attached a patch to this bug report that fixes this. Note that any additional links that were manually created by the administrator will not be touched, only those that were created by deb-systemd-helper in the first place. The only use case that is not covered by this patch is if an administrator wanted to keep a link that was auto-created (there is no way to distinguish them), but that seems to be quite unlikely (and the administrator could re-create it later - and it would then stay, even if the same version of the package were to be installed again - only upgrades will remove links). I've also attached a trivial package in two versions to test this. They change all 3 options (WantedBy=, Also= and Alias=) to test everything at the same time. Just extract the source tarballs and build the native packages if you want to test this. Please change the commit message of the patch so that it reflects the bug number it closes when you apply it to git. Regards, Christian -- System Information: Debian Release: stretch/sid APT prefers unstable APT policy: (500, 'unstable'), (500, 'testing') Architecture: amd64 (x86_64) Kernel: Linux 4.1.0-2-amd64 (SMP w/1 CPU core) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) Versions of packages init-system-helpers depends on: ii perl-base 5.20.2-6 init-system-helpers recommends no packages. init-system-helpers suggests no packages. -- no debconf information
From 38aa3cc8c1390a9ae5ba047faf4cae3b3674286c Mon Sep 17 00:00:00 2001 From: Christian Seiler <christ...@iwakd.de> Date: Thu, 27 Aug 2015 22:13:15 +0200 Subject: [PATCH] deb-systemd-helper: Remove obsolete links on package upgrades For changes in WantedBy=, Also= and Alias= it could be the case that links become optional when a package is upgraded and deb-systemd-helper is called. Specifically, if something is removed from those lists, the old links would stay around. This patch addresses that by calculating the list of links in the state file on upgrades that are not present in the newly calculated link closure. Those links were part of the old link closure, so they were in WantedBy=, Also= or Alias= lines of the old package - so they should now be removed, since they are not anymore part of those lines. Any additional links that the administrator may have added themselves in other places (other .wants/ directories, for example) will not be touched by this logic. Closes: #....... --- script/deb-systemd-helper | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/script/deb-systemd-helper b/script/deb-systemd-helper index 2a87cb4..0210814 100755 --- a/script/deb-systemd-helper +++ b/script/deb-systemd-helper @@ -224,12 +224,16 @@ sub make_systemd_links { my $dsh_state = dsh_state_path($scriptname); my @links = get_link_closure($scriptname, $service_path); + my @oldlinks = state_file_entries($dsh_state); + for my $link (@links) { my $service_path = $link->{dest}; my $service_link = $link->{src}; record_in_statefile($dsh_state, $service_link); + @oldlinks = grep { $_ ne $service_link } @oldlinks; + my $statefile = $service_link; $statefile =~ s,^/etc/systemd/system/,$enabled_state_dir/,; next if -e $statefile; @@ -251,6 +255,23 @@ sub make_systemd_links { close($fh); } + debug "Old links to remove (due to modified service file): " . + Data::Dumper::Dumper([ @oldlinks ]); + + # On package upgrade, some old links might be in need of removal + # (because e.g. WantedBy= changed), so remove those, if they exist. + for my $link (@oldlinks) { + # If the administrator deleted the real link themselves, don't + # remove the state links (to remember enablement state). + next unless -l $link; + + my $link_state = $link; + $link_state =~ s,^/etc/systemd/system/,$enabled_state_dir/,; + unlink($link_state); + + unlink($link) or + print STDERR "$0: unable to remove '$link': $!\n"; + } } # In contrary to make_systemd_links(), which only modifies the state file in an -- 2.5.0
testpkg_42.tar.xz
Description: application/xz
testpkg_43.tar.xz
Description: application/xz
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Pkg-systemd-maintainers mailing list Pkg-systemd-maintainers@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-systemd-maintainers