From 792e151f442fb3a8cc9dd9a2c22602b76f0c96e8 Mon Sep 17 00:00:00 2001 From: Toni Lopes Date: Mon, 13 May 2024 20:12:01 +0100 Subject: [PATCH] systemd-systemctl: Fix WantedBy processing An empty string assignment to WantedBy should clear all prior WantedBy settings. This matches behavior of the current systemd implementation. Signed-off-by: Toni Lopes --- meta/recipes-core/systemd/systemd-systemctl/systemctl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl index 0fd7e240853..7fe751b397c 100755 --- a/meta/recipes-core/systemd/systemd-systemctl/systemctl +++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl @@ -26,6 +26,9 @@ locations = list() class SystemdFile(): """Class representing a single systemd configuration file""" + + _clearable_keys = ['WantedBy'] + def __init__(self, root, path, instance_unit_name): self.sections = dict() self._parse(root, path) @@ -80,6 +83,14 @@ class SystemdFile(): v = m.group('value') if k not in section: section[k] = list() + + # If we come across a "key=" line for a "clearable key", then + # forget all preceding assignments. This works because we are + # processing files in correct parse order. + if k in self._clearable_keys and not v: + del section[k] + continue + section[k].extend(v.split()) def get(self, section, prop):