summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd-systemctl
diff options
context:
space:
mode:
authorNick Potenski <nick.potenski@garmin.com>2022-06-15 14:32:19 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-06-24 23:57:46 +0100
commit0b84202a2b6d63ae65e7718bfbd4ae67ec062cd9 (patch)
treecfbecb911d6213bb6c9f8a93b76566b84f1ad1d1 /meta/recipes-core/systemd/systemd-systemctl
parentae90fa778a41dedfbf55f3f89dc8c3968b17eaaf (diff)
downloadpoky-0b84202a2b6d63ae65e7718bfbd4ae67ec062cd9.tar.gz
systemd: systemd-systemctl: Support instance conf files during enable
Add ability to parse instance-specific conf files when enabling an instance of a templated unit during postinstall. (From OE-Core rev: f2d59bf2240eaf4c483edc4feb6e5d66b8dc387f) Signed-off-by: Nick Potenski <nick.potenski@garmin.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit baa0ecf3271008cf60cd830c54a71f191aebb81c) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-core/systemd/systemd-systemctl')
-rwxr-xr-xmeta/recipes-core/systemd/systemd-systemctl/systemctl14
1 files changed, 11 insertions, 3 deletions
diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
index 990de1ab39..6aa2e20465 100755
--- a/meta/recipes-core/systemd/systemd-systemctl/systemctl
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -11,6 +11,7 @@ import re
11import sys 11import sys
12 12
13from collections import namedtuple 13from collections import namedtuple
14from itertools import chain
14from pathlib import Path 15from pathlib import Path
15 16
16version = 1.0 17version = 1.0
@@ -25,12 +26,16 @@ locations = list()
25 26
26class SystemdFile(): 27class SystemdFile():
27 """Class representing a single systemd configuration file""" 28 """Class representing a single systemd configuration file"""
28 def __init__(self, root, path): 29 def __init__(self, root, path, instance_unit_name):
29 self.sections = dict() 30 self.sections = dict()
30 self._parse(root, path) 31 self._parse(root, path)
31 dirname = os.path.basename(path.name) + ".d" 32 dirname = os.path.basename(path.name) + ".d"
32 for location in locations: 33 for location in locations:
33 for path2 in sorted((root / location / "system" / dirname).glob("*.conf")): 34 files = (root / location / "system" / dirname).glob("*.conf")
35 if instance_unit_name:
36 inst_dirname = instance_unit_name + ".d"
37 files = chain(files, (root / location / "system" / inst_dirname).glob("*.conf"))
38 for path2 in sorted(files):
34 self._parse(root, path2) 39 self._parse(root, path2)
35 40
36 def _parse(self, root, path): 41 def _parse(self, root, path):
@@ -193,8 +198,11 @@ class SystemdUnit():
193 # if we're enabling an instance, first extract the actual instance 198 # if we're enabling an instance, first extract the actual instance
194 # then figure out what the template unit is 199 # then figure out what the template unit is
195 template = re.match(r"[^@]+@(?P<instance>[^\.]*)\.", self.unit) 200 template = re.match(r"[^@]+@(?P<instance>[^\.]*)\.", self.unit)
201 instance_unit_name = None
196 if template: 202 if template:
197 instance = template.group('instance') 203 instance = template.group('instance')
204 if instance != "":
205 instance_unit_name = self.unit
198 unit = re.sub(r"@[^\.]*\.", "@.", self.unit, 1) 206 unit = re.sub(r"@[^\.]*\.", "@.", self.unit, 1)
199 else: 207 else:
200 instance = None 208 instance = None
@@ -206,7 +214,7 @@ class SystemdUnit():
206 # ignore aliases 214 # ignore aliases
207 return 215 return
208 216
209 config = SystemdFile(self.root, path) 217 config = SystemdFile(self.root, path, instance_unit_name)
210 if instance == "": 218 if instance == "":
211 try: 219 try:
212 default_instance = config.get('Install', 'DefaultInstance')[0] 220 default_instance = config.get('Install', 'DefaultInstance')[0]