summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKhang D Nguyen <khangng@os.amperecomputing.com>2025-08-20 09:55:24 +0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-08-21 10:29:56 +0100
commit2ba3de20783e07728fb1409002fea33d21ac54fa (patch)
tree00de4aaae24cc8e5af07c474ee030ca110548b8e
parent11817b180e68a64cf22d0417f8d647e382ca758d (diff)
downloadpoky-2ba3de20783e07728fb1409002fea33d21ac54fa.tar.gz
systemd.bbclass: deduplicate template and instance lines in preset file
If SYSTEMD_SERVICE contains both template and instance names, the preset file will contain two lines: one describing the template name and one describing the instance names. This is problematic because systemd.preset only use the first matching one [1], leading to the instances not getting enabled. For example, openbmc's obmc-console recipe has the following final SYSTEMD_SERVICE variable: ``` SYSTEMD_SERVICE:obmc-console = " \ obmc-console@.service \ obmc-console-ssh@.service \ obmc-console-ssh@2200.service \ " ``` The resulting preset file will contain lines with the same name: ``` enable obmc-console@.service enable obmc-console-ssh@.service enable obmc-console-ssh@.service 2200 ``` Fix this by interpreting the template name as a special case of empty instances. Tested: preset files are generated correctly: ``` enable obmc-console@.service enable obmc-console-ssh@.service 2200 ``` [1]: https://www.freedesktop.org/software/systemd/man/257/systemd.preset.html#Preset%20File%20Format Fixes: f33d9b1f434e ("systemd.bbclass: generate preset for templates") (From OE-Core rev: 7cdf10840c200a327b6336775698342af7212ee4) Signed-off-by: Khang D Nguyen <khangng@os.amperecomputing.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes-recipe/systemd.bbclass7
1 files changed, 5 insertions, 2 deletions
diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
index 12c59647be..0e9f7cfa33 100644
--- a/meta/classes-recipe/systemd.bbclass
+++ b/meta/classes-recipe/systemd.bbclass
@@ -249,9 +249,12 @@ python systemd_populate_packages() {
249 (servicename, instance, service_type) = re.split('[@.]', service) 249 (servicename, instance, service_type) = re.split('[@.]', service)
250 template_services.setdefault(servicename + '@.' + service_type, []).append(instance) 250 template_services.setdefault(servicename + '@.' + service_type, []).append(instance)
251 else: 251 else:
252 fd.write("%s %s\n" % (action,service)) 252 template_services.setdefault(service, [])
253 for template, instances in template_services.items(): 253 for template, instances in template_services.items():
254 fd.write("%s %s %s\n" % (action, template, ' '.join(instances))) 254 if instances:
255 fd.write("%s %s %s\n" % (action, template, ' '.join(instances)))
256 else:
257 fd.write("%s %s\n" % (action, template))
255 d.appendVar("FILES:%s" % pkg, ' ' + oe.path.join(d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg))) 258 d.appendVar("FILES:%s" % pkg, ' ' + oe.path.join(d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg)))
256 259
257 # Run all modifications once when creating package 260 # Run all modifications once when creating package