Bug#985787: init-system-helpers: deb-systemd-helper - incoherent enable after WantedBy change

Marcin Szewczyk debian.bugreport at wodny.org
Wed Mar 24 12:52:01 GMT 2021


On Tue, Mar 23, 2021 at 04:20:18PM +0100, Michael Biebl wrote:
> Am 23.03.21 um 15:32 schrieb Marcin Szewczyk:
> > Package: init-system-helpers
> > Version: 1.56+nmu1
> > Severity: normal
> > 
> > I use debhelper to install and enable systemd user units. I noticed that
> > after changing the `WantedBy` value from default.target to
> > graphical.target the new symlink was not created.
> 
> This happens rarely enough, that adding explicit support for that in i-s-h
> is probably not worth the complications.
> That said, if someone can come up with a clean patch to do that, I'm happy
> to take a look.

I attach a patch (against debian/1.60). It differs from the one in
#797108. Maybe it goes in an acceptable direction. Please take a look if
you have some time.

Pardon my Perl. I have not used it for 15 years.

>From the commit message:
> take changes in references to units into account
> 
> - react to changes eg. in WantedBy
> - enable: add symlinks to added units
> - update-state: remove state files of no longer managed links (garbage
>   collection)

-- 
Marcin Szewczyk
http://wodny.org
-------------- next part --------------
>From bfb0aecc46009cca72f5a3c1b0ca3fb2a2280048 Mon Sep 17 00:00:00 2001
From: Marcin Szewczyk <marcin.szewczyk at wodny.org>
Date: Wed, 24 Mar 2021 13:35:22 +0100
Subject: [PATCH] take changes in references to units into account

- react to changes eg. in WantedBy
- enable: add symlinks to added units
- update-state: remove state files of no longer managed links (garbage
  collection)
---
 script/deb-systemd-helper | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/script/deb-systemd-helper b/script/deb-systemd-helper
index 7e929ed..e626380 100755
--- a/script/deb-systemd-helper
+++ b/script/deb-systemd-helper
@@ -250,6 +250,11 @@ sub no_link_installed {
     my ($scriptname, $service_path) = @_;
 
     my @links = get_link_closure($scriptname, $service_path);
+    # Previous package version might have managed additional links.
+    # Take them into account to determine if the service was previously enabled.
+    my $dsh_state = dsh_state_path($scriptname);
+    my @dsh_links = map { { src => $_ } } state_file_entries($dsh_state);
+    push(@links, @dsh_links);
     my @existing_links = grep { -l $_->{src} } @links;
 
     return (@existing_links == 0);
@@ -329,6 +334,7 @@ sub update_state {
 
     my $dsh_state = dsh_state_path($scriptname);
     my @links = get_link_closure($scriptname, $service_path);
+    my @dsh_links = state_file_entries($dsh_state);
 
     debug "Old state file contents: " .
         Data::Dumper::Dumper([ state_file_entries($dsh_state) ]);
@@ -344,6 +350,14 @@ sub update_state {
     }
     close($outfh);
 
+    # Remove state files of previously managed links if they are no longer managed.
+    my %links = map { $_->{src} => 1 } @links;
+    for my $dsh_link (@dsh_links) {
+        my $statefile = $dsh_link;
+        $statefile =~ s,^/etc/systemd/$instance/,$enabled_state_dir/,;
+        unlink($statefile) unless exists($links{$dsh_link});
+    }
+
     debug "Renaming temp file $tmpname to state file $dsh_state";
     rename($tmpname, $dsh_state) or
         error("Unable to move $tmpname to $dsh_state");
-- 
2.25.0



More information about the Pkg-systemd-maintainers mailing list