Bug#801822: deb-systemd-helper does not support template units (e.g. foo at .service)

Victor Westerhuis victor at westerhu.is
Thu Feb 3 15:44:28 GMT 2022


Package: init-system-helpers
Version: 1.61
Followup-For: Bug #801822
Control: tags -1 patch

I've opened a merge request on Salsa with another possible fix.
It works for me locally, but I would like any feedback if I made a mistake somewhere.

I've attached the patch as an attachment and the MR is at 
https://salsa.debian.org/debian/init-system-helpers/-/merge_requests/20.


-- System Information:
Debian Release: bookworm/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable'), (100, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 5.15.0-3-amd64 (SMP w/4 CPU threads)
Locale: LANG=en_NL.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE=en_GB:en_US:en:nl_NL:nl
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages init-system-helpers depends on:
ii  perl-base  5.32.1-6

init-system-helpers recommends no packages.

init-system-helpers suggests no packages.

Versions of packages init-system-helpers is related to:
pn  insserv  <none>

-- no debconf information

-- debsums errors found:
debsums: changed file /usr/sbin/update-rc.d (from init-system-helpers package)
-------------- next part --------------
diff --git a/script/deb-systemd-helper b/script/deb-systemd-helper
index 7e929ed..c27e5da 100755
--- a/script/deb-systemd-helper
+++ b/script/deb-systemd-helper
@@ -192,8 +192,11 @@ sub get_link_closure {
     my ($scriptname, $service_path) = @_;
 
     my @links;
+    my @wants_dirs;
 
     my $unit_name = basename($service_path);
+    my $template = $unit_name =~ /\@\.\w+$/;
+    my $default_instance = $unit_name unless $template;
 
     # The keys parsed from the unit file below can only have unit names
     # as values. Since unit names can't have whitespace in systemd,
@@ -210,7 +213,7 @@ sub get_link_closure {
                 my $wants_dir = "/etc/systemd/$instance/$value";
                 $wants_dir .= '.wants' if $1 eq 'WantedBy';
                 $wants_dir .= '.requires' if $1 eq 'RequiredBy';
-                push @links, { dest => $service_path, src => "$wants_dir/$scriptname" };
+                push @wants_dirs, "$wants_dir/";
             }
         }
 
@@ -231,9 +234,20 @@ sub get_link_closure {
                 }
             }
         }
+
+        if ($template && $line =~ /^\s*DefaultInstance=\s*(["']?+)(.+)\g1\s*$/i) {
+            $default_instance = $2;
+            $default_instance = $unit_name =~ s/^(.*\@)(\.\w+)$/$1$default_instance$2/r;
+        }
     }
     close($fh);
 
+    if ($default_instance) {
+        for my $wants_dir (@wants_dirs) {
+            push @links, { dest => $service_path, src => $wants_dir . $default_instance };
+        }
+    }
+
     return @links;
 }
 


More information about the Pkg-systemd-maintainers mailing list