Skip to contentSkip to conversation

systemd-systemctl: support instance expansion in WantedBy

PATCH New Ian Ray 1 participant 1 message Jun 11, 2023

lore
Share & tools
lore

Ian Ray

author
#0 lore raw

PATCH 1/1 systemd-systemctl: support instance expansion in WantedBy

Refactor _process_deps to expand systemd instance specifier "%i" to the template instance.

This change expands on prior commit e510222b57 ("systemd-systemctl: fix instance template WantedBy symlink construction") by substituting every "%i" pattern-match with the instance name.

The regexp handles the following cases:

* svc-wants@%i.service

* sys-subsystem-net-devices-%i.device

---
 meta/recipes-core/systemd/systemd-systemctl/systemctl | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
meta/recipes-core/systemd/systemd-systemctl/systemctl +2 -7
index b45a2dc..514f747 100755
@@ -201,13 +201,8 @@ class SystemdUnit():
         target = ROOT / location.relative_to(self.root)
         try:
             for dependent in config.get('Install', prop):
-                # determine whether or not dependent is a template with an actual
-                # instance (i.e. a '@%i')
-                dependent_is_template = re.match(r"[^@]+@(?P<instance>[^\.]*)\.", dependent)
-                if dependent_is_template:
-                    # if so, replace with the actual instance to achieve
-                    # [email protected]/[email protected]
-                    dependent = re.sub(dependent_is_template.group('instance'), instance, dependent, 1)
+                # expand any %i to instance (ignoring escape sequence %%)
+                dependent = re.sub("([^%](%%)*)%i", "\\1{}".format(instance), dependent)
                 wants = systemdir / "{}.{}".format(dependent, dirstem) / service
                 add_link(wants, target)
 
Signature · 1 line
2.10.1