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-17 17:57:44 +0100
commit01aaeb444f17a34a53a29dbdc3d8640b3ffdbf93 (patch)
treebca71562aa9e2b5790a6a5051b3beff461c7b0f2 /meta/recipes-core/systemd/systemd-systemctl
parent858f7e9d36ffb4f86033a12c50e5decf55a741b7 (diff)
downloadpoky-01aaeb444f17a34a53a29dbdc3d8640b3ffdbf93.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: baa0ecf3271008cf60cd830c54a71f191aebb81c) 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>
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 6324319a45..6d19666d82 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):
@@ -195,8 +200,11 @@ class SystemdUnit():
195 # if we're enabling an instance, first extract the actual instance 200 # if we're enabling an instance, first extract the actual instance
196 # then figure out what the template unit is 201 # then figure out what the template unit is
197 template = re.match(r"[^@]+@(?P<instance>[^\.]*)\.", self.unit) 202 template = re.match(r"[^@]+@(?P<instance>[^\.]*)\.", self.unit)
203 instance_unit_name = None
198 if template: 204 if template:
199 instance = template.group('instance') 205 instance = template.group('instance')
206 if instance != "":
207 instance_unit_name = self.unit
200 unit = re.sub(r"@[^\.]*\.", "@.", self.unit, 1) 208 unit = re.sub(r"@[^\.]*\.", "@.", self.unit, 1)
201 else: 209 else:
202 instance = None 210 instance = None
@@ -208,7 +216,7 @@ class SystemdUnit():
208 # ignore aliases 216 # ignore aliases
209 return 217 return
210 218
211 config = SystemdFile(self.root, path) 219 config = SystemdFile(self.root, path, instance_unit_name)
212 if instance == "": 220 if instance == "":
213 try: 221 try:
214 default_instance = config.get('Install', 'DefaultInstance')[0] 222 default_instance = config.get('Install', 'DefaultInstance')[0]