systemd-systemctl: fix instance template WantedBy symlink construction
cover systemd-systemctl: fix instance template WantedBy symlink construction
Issue was reported a while ago through https://lists.openembedded.org/g/openembedded-core/message/178423
The patch is verified using a few services constructed for the purpose, available through https://github.com/mnsgs/meta-systemd-test
Martin Siegumfeldt (1):
systemd-systemctl: fix instance template WantedBy symlink construction
.../systemd/systemd-systemctl/systemctl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
Signature · 5 lines
2.25.1 ________________________ This email was scanned by Bitdefender
PATCH 1/1 systemd-systemctl: fix instance template WantedBy symlink construction
Fix issue of the below instance template systemd service dependency
[Install]
WantedBy=svc-wants@%i.service
creating the symlink (instance "a" example)
/etc/systemd/system/svc-wants@%i.service.wants/[email protected]
which should be
/etc/systemd/system/[email protected]/[email protected]
as implemented by this change.
The functionality appears regressed just after "thud" baseline when the logic was refactored from shell script into python (commit 925e30cb104ece7bfa48b78144e758a46dc9ec3f)
--- .../systemd/systemd-systemctl/systemctl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
meta/recipes-core/systemd/systemd-systemctl/systemctl +10 -3
@@ -195,12 +195,19 @@ class SystemdUnit(): raise SystemdUnitNotFoundError(self.root, unit) - def _process_deps(self, config, service, location, prop, dirstem): + def _process_deps(self, config, service, location, prop, dirstem, instance): systemdir = self.root / SYSCONFDIR / "systemd" / "system" 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) wants = systemdir / "{}.{}".format(dependent, dirstem) / service add_link(wants, target)
@@ -240,8 +247,8 @@ class SystemdUnit(): else: service = self.unit - self._process_deps(config, service, path, 'WantedBy', 'wants') - self._process_deps(config, service, path, 'RequiredBy', 'requires') + self._process_deps(config, service, path, 'WantedBy', 'wants', instance) + self._process_deps(config, service, path, 'RequiredBy', 'requires', instance) try: for also in config.get('Install', 'Also'):
Signature · 5 lines
2.25.1 ________________________ This email was scanned by Bitdefender