diff options
| author | Artur Kowalski <arturkow2000@gmail.com> | 2025-01-20 13:46:03 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-01-21 12:07:56 +0000 |
| commit | 284450ed971fc34085824b4c51f879d4f8cfac2d (patch) | |
| tree | 246e2a24940e212370c367fdf4dbde243a53f16a | |
| parent | a3302b821600119b3e346ed10f0ffa3c3533e77c (diff) | |
| download | poky-284450ed971fc34085824b4c51f879d4f8cfac2d.tar.gz | |
systemd.bbclass: properly handle user units in systemd_create_presets
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.
(From OE-Core rev: 0218542d80723ec314a648af8e9649806c3a51aa)
Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/classes-recipe/systemd.bbclass | 29 |
1 files 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): | |||
| 102 | d.getVar("systemd_system_unitdir"), | 102 | d.getVar("systemd_system_unitdir"), |
| 103 | ] | 103 | ] |
| 104 | 104 | ||
| 105 | def systemd_service_exists(service, user, d): | ||
| 106 | searchpaths = systemd_service_searchpaths(user, d) | ||
| 107 | path, _ = systemd_service_path(service, searchpaths, d) | ||
| 108 | |||
| 109 | return path != '' | ||
| 110 | |||
| 105 | python systemd_populate_packages() { | 111 | python systemd_populate_packages() { |
| 106 | import re | 112 | import re |
| 107 | import shlex | 113 | import shlex |
| @@ -197,13 +203,27 @@ python systemd_populate_packages() { | |||
| 197 | bb.fatal("Didn't find service unit '{0}', specified in SYSTEMD_SERVICE:{1}. {2}".format( | 203 | bb.fatal("Didn't find service unit '{0}', specified in SYSTEMD_SERVICE:{1}. {2}".format( |
| 198 | service, pkg_systemd, "Also looked for service unit '{0}'.".format(base) if base is not None else "")) | 204 | service, pkg_systemd, "Also looked for service unit '{0}'.".format(base) if base is not None else "")) |
| 199 | 205 | ||
| 200 | def systemd_create_presets(pkg, action): | 206 | def systemd_create_presets(pkg, action, user): |
| 201 | presetf = oe.path.join(d.getVar("PKGD"), d.getVar("systemd_unitdir"), "system-preset/98-%s.preset" % pkg) | 207 | # Check there is at least one service of given type (system/user), don't |
| 208 | # create empty files. | ||
| 209 | needs_preset = False | ||
| 210 | for service in d.getVar('SYSTEMD_SERVICE:%s' % pkg).split(): | ||
| 211 | if systemd_service_exists(service, user, d): | ||
| 212 | needs_preset = True | ||
| 213 | break | ||
| 214 | |||
| 215 | if not needs_preset: | ||
| 216 | return | ||
| 217 | |||
| 218 | prefix = "user" if user else "system" | ||
| 219 | presetf = oe.path.join(d.getVar("PKGD"), d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg)) | ||
| 202 | bb.utils.mkdirhier(os.path.dirname(presetf)) | 220 | bb.utils.mkdirhier(os.path.dirname(presetf)) |
| 203 | with open(presetf, 'a') as fd: | 221 | with open(presetf, 'a') as fd: |
| 204 | for service in d.getVar('SYSTEMD_SERVICE:%s' % pkg).split(): | 222 | for service in d.getVar('SYSTEMD_SERVICE:%s' % pkg).split(): |
| 223 | if not systemd_service_exists(service, user, d): | ||
| 224 | continue | ||
| 205 | fd.write("%s %s\n" % (action,service)) | 225 | fd.write("%s %s\n" % (action,service)) |
| 206 | d.appendVar("FILES:%s" % pkg, ' ' + oe.path.join(d.getVar("systemd_unitdir"), "system-preset/98-%s.preset" % pkg)) | 226 | d.appendVar("FILES:%s" % pkg, ' ' + oe.path.join(d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg))) |
| 207 | 227 | ||
| 208 | # Run all modifications once when creating package | 228 | # Run all modifications once when creating package |
| 209 | if os.path.exists(d.getVar("D")): | 229 | if os.path.exists(d.getVar("D")): |
| @@ -213,7 +233,8 @@ python systemd_populate_packages() { | |||
| 213 | systemd_generate_package_scripts(pkg) | 233 | systemd_generate_package_scripts(pkg) |
| 214 | action = get_package_var(d, 'SYSTEMD_AUTO_ENABLE', pkg) | 234 | action = get_package_var(d, 'SYSTEMD_AUTO_ENABLE', pkg) |
| 215 | if action in ("enable", "disable"): | 235 | if action in ("enable", "disable"): |
| 216 | systemd_create_presets(pkg, action) | 236 | systemd_create_presets(pkg, action, False) |
| 237 | systemd_create_presets(pkg, action, True) | ||
| 217 | elif action not in ("mask", "preset"): | 238 | elif action not in ("mask", "preset"): |
| 218 | bb.fatal("SYSTEMD_AUTO_ENABLE:%s '%s' is not 'enable', 'disable', 'mask' or 'preset'" % (pkg, action)) | 239 | bb.fatal("SYSTEMD_AUTO_ENABLE:%s '%s' is not 'enable', 'disable', 'mask' or 'preset'" % (pkg, action)) |
| 219 | systemd_check_services() | 240 | systemd_check_services() |
