From: "Artur Kowalski" <arturkow2000@gmail.com>
To: openembedded-core@lists.openembedded.org
Cc: Artur Kowalski <arturkow2000@gmail.com>
Subject: [PATCH v3 5/8] systemd.bbclass: properly handle user units in systemd_create_presets
Date: Mon, 20 Jan 2025 13:46:03 +0100 [thread overview]
Message-ID: <20250120124605.263817-7-arturkow2000@gmail.com> (raw)
In-Reply-To: <20250120124605.263817-2-arturkow2000@gmail.com>
Previously user units were handled the same way as system units, that
is all preset files were created in system-preset directory, but user
presets should be in user-preset directory.
Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
---
meta/classes-recipe/systemd.bbclass | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
index a3c2c6eb20..592f15a4b7 100644
--- a/meta/classes-recipe/systemd.bbclass
+++ b/meta/classes-recipe/systemd.bbclass
@@ -102,6 +102,12 @@ def systemd_service_searchpaths(user, d):
d.getVar("systemd_system_unitdir"),
]
+def systemd_service_exists(service, user, d):
+ searchpaths = systemd_service_searchpaths(user, d)
+ path, _ = systemd_service_path(service, searchpaths, d)
+
+ return path != ''
+
python systemd_populate_packages() {
import re
import shlex
@@ -197,13 +203,27 @@ python systemd_populate_packages() {
bb.fatal("Didn't find service unit '{0}', specified in SYSTEMD_SERVICE:{1}. {2}".format(
service, pkg_systemd, "Also looked for service unit '{0}'.".format(base) if base is not None else ""))
- def systemd_create_presets(pkg, action):
- presetf = oe.path.join(d.getVar("PKGD"), d.getVar("systemd_unitdir"), "system-preset/98-%s.preset" % pkg)
+ def systemd_create_presets(pkg, action, user):
+ # Check there is at least one service of given type (system/user), don't
+ # create empty files.
+ needs_preset = False
+ for service in d.getVar('SYSTEMD_SERVICE:%s' % pkg).split():
+ if systemd_service_exists(service, user, d):
+ needs_preset = True
+ break
+
+ if not needs_preset:
+ return
+
+ prefix = "user" if user else "system"
+ presetf = oe.path.join(d.getVar("PKGD"), d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg))
bb.utils.mkdirhier(os.path.dirname(presetf))
with open(presetf, 'a') as fd:
for service in d.getVar('SYSTEMD_SERVICE:%s' % pkg).split():
+ if not systemd_service_exists(service, user, d):
+ continue
fd.write("%s %s\n" % (action,service))
- d.appendVar("FILES:%s" % pkg, ' ' + oe.path.join(d.getVar("systemd_unitdir"), "system-preset/98-%s.preset" % pkg))
+ d.appendVar("FILES:%s" % pkg, ' ' + oe.path.join(d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg)))
# Run all modifications once when creating package
if os.path.exists(d.getVar("D")):
@@ -213,7 +233,8 @@ python systemd_populate_packages() {
systemd_generate_package_scripts(pkg)
action = get_package_var(d, 'SYSTEMD_AUTO_ENABLE', pkg)
if action in ("enable", "disable"):
- systemd_create_presets(pkg, action)
+ systemd_create_presets(pkg, action, False)
+ systemd_create_presets(pkg, action, True)
elif action not in ("mask", "preset"):
bb.fatal("SYSTEMD_AUTO_ENABLE:%s '%s' is not 'enable', 'disable', 'mask' or 'preset'" % (pkg, action))
systemd_check_services()
--
2.47.1
next prev parent reply other threads:[~2025-01-20 14:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-20 12:45 [PATCH v3 0/8] Systemd user presets support Artur Kowalski
2025-01-20 12:45 ` [PATCH v3 1/8] systemd-systemctl: add support for --global flag Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 2/8] systemd.bbclass: add ${sysconfdir}/systemd/user to search path Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 3/8] systemd.bbclass: factor out service lookup logic into separate function Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 4/8] systemd.bbclass: introduce systemd_service_searchpaths() Artur Kowalski
2025-01-20 12:46 ` Artur Kowalski [this message]
2025-01-20 12:46 ` [PATCH v3 6/8] systemd.bbclass: update postinst and prerm hooks Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 7/8] systemd.bbclass: support user units in " Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 8/8] image.bbclass: enable systemd user services Artur Kowalski
2025-01-24 12:51 ` [OE-core] " Markus Volk
2025-01-24 18:24 ` Artur Kowalski
2025-01-24 21:24 ` Markus Volk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250120124605.263817-7-arturkow2000@gmail.com \
--to=arturkow2000@gmail.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox