From patchwork Mon Jan 20 12:45:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F272EC0218E for ; Mon, 20 Jan 2025 14:00:13 +0000 (UTC) Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by mx.groups.io with SMTP id smtpd.web11.35714.1737377272828660472 for ; Mon, 20 Jan 2025 04:47:53 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hbJ6pIyL; spf=pass (domain: gmail.com, ip: 209.85.167.51, mailfrom: arturkow2000@gmail.com) Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-5401bd6ccadso4406236e87.2 for ; Mon, 20 Jan 2025 04:47:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737377271; x=1737982071; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YemSaV1dfOrNvGXjnyX1/wBtLsVbmiKiA5SY2t8+UBU=; b=hbJ6pIyL4cIFE6iWn1fKcy/mmcZmVsB7iO9p3XQwmvUs48Xe8dvRmj5Ermg+3LvXfN 77uV6YzyUFftpASyoz/vK/HMKZeDoFcfqbgLTBCrgp7YgkpcuG9ZbrjUarXv1TrImhrD 1tyUGbHkSc8TfakSo3JiJhq+i3eDd880WvrIqwdaVlJVYyU4hXjheLKC6TOlkbo9QxMl mcB1EyJa/WwVWI/9bUgipQRW9SFgiQeFrienpTHxPYQTFqtWylQ32m4TrvbmHupVepmX vD7f0sqHOKtz/SWTKsGh5nlYxuOBm4hFahASAQ1+5AabKPaCIJ2vEqLpvBDp/mYwoKId AXOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737377271; x=1737982071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YemSaV1dfOrNvGXjnyX1/wBtLsVbmiKiA5SY2t8+UBU=; b=wTKRp9gQ6YUVW7KMUPJ8qgvcPg5RVABb70HOHP7Cm6vwibM9mU/C/w6GBqbtZS2Ge1 ssMZcjR5m2bvCENoKK4nyvmdCbUqCBWnkGIWKpwDXSQMIORqTJxBtSiqX7mZy5fEfL/d EyjxZKA+NCy7ebs9+nXb8CmRVmhVWdWDnADAeAvAotFTtNTQb1PCHodqpcFiXsnQYUn7 SEtd6JHV23neZw+stKhywrTb4Gr6OVN4L0zED3wLRJxf7YhbvwZPlatjsrn5zK6w17fw 2FRYrfZQvrStcg/FBjvlr9uQJcTKvFfYPNuz9uBTTN0AOLP0kInI91JUvmVLPfEUjnKv JK/g== X-Gm-Message-State: AOJu0Yz3gkDrpDqiu2dhIagU2g7clZZsDDaFYpZR9+scjgPuF5LcAW1c fBfnxNy+1HFknvOJUfyYggwIfhCT0gqH2RWByFc4HGjbeGY3G+PkixHF3Q== X-Gm-Gg: ASbGncsufc8J5H5wuea3udXBPerCXw3TEQrM2hycGn4RYjsej9OSDsgQ/c5ouUzxb0y O3jaCTxee9kKYWABTAhYGAg/90bKeqxPnEfhWxPCaBlaxH5ZKddE79cVx1acVkIn9iKIYUI2PiK 54EkudRR4pvfaMlc/8qfNCrlzlJx7lmh8QsfR7GouJFjydKecB0tJK5g91kD0yU9uilsAw3Xd8L 8ABe8v9E/ub02xVgYmzdJO+oZ32Qid+7pPXvNAEHjWE20E2HcLZ7X+5/8U6ieva+SRUa/DK9DXm Tw== X-Google-Smtp-Source: AGHT+IF7TM34vWIFDXJb9Vs/0zvVwxpeDrjhG3mGYbwvLLLUE3qDub9ZgAmENmqvhW9Zx4F2etdnwA== X-Received: by 2002:ac2:4541:0:b0:53e:389d:8ce4 with SMTP id 2adb3069b0e04-5439c281f4fmr3868307e87.34.1737377270265; Mon, 20 Jan 2025 04:47:50 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:23ed:c831:8228:ebaa]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5439af0742csm1307523e87.37.2025.01.20.04.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 04:47:49 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v3 1/8] systemd-systemctl: add support for --global flag Date: Mon, 20 Jan 2025 13:45:59 +0100 Message-ID: <20250120124605.263817-3-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120124605.263817-2-arturkow2000@gmail.com> References: <20250120124605.263817-2-arturkow2000@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 20 Jan 2025 14:00:13 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/210032 The flag is similar to --user flag as it causes systemctl to operate on user units, but it performs operations globally for all users. This is required for user presets support. Signed-off-by: Artur Kowalski --- .../systemd/systemd-systemctl/systemctl | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl index 2229bc7b6d..81c246a5b2 100755 --- a/meta/recipes-core/systemd/systemd-systemctl/systemctl +++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl @@ -29,15 +29,15 @@ class SystemdFile(): _clearable_keys = ['WantedBy'] - def __init__(self, root, path, instance_unit_name): + def __init__(self, root, path, instance_unit_name, unit_type): self.sections = dict() self._parse(root, path) dirname = os.path.basename(path.name) + ".d" for location in locations: - files = (root / location / "system" / dirname).glob("*.conf") + files = (root / location / unit_type / dirname).glob("*.conf") if instance_unit_name: inst_dirname = instance_unit_name + ".d" - files = chain(files, (root / location / "system" / inst_dirname).glob("*.conf")) + files = chain(files, (root / location / unit_type / inst_dirname).glob("*.conf")) for path2 in sorted(files): self._parse(root, path2) @@ -182,21 +182,22 @@ class SystemdUnitNotFoundError(Exception): class SystemdUnit(): - def __init__(self, root, unit): + def __init__(self, root, unit, unit_type): self.root = root self.unit = unit + self.unit_type = unit_type self.config = None def _path_for_unit(self, unit): for location in locations: - path = self.root / location / "system" / unit + path = self.root / location / self.unit_type / unit if path.exists() or path.is_symlink(): return path raise SystemdUnitNotFoundError(self.root, unit) def _process_deps(self, config, service, location, prop, dirstem, instance): - systemdir = self.root / SYSCONFDIR / "systemd" / "system" + systemdir = self.root / SYSCONFDIR / "systemd" / self.unit_type target = ROOT / location.relative_to(self.root) try: @@ -229,7 +230,7 @@ class SystemdUnit(): # ignore aliases return - config = SystemdFile(self.root, path, instance_unit_name) + config = SystemdFile(self.root, path, instance_unit_name, self.unit_type) if instance == "": try: default_instance = config.get('Install', 'DefaultInstance')[0] @@ -250,14 +251,14 @@ class SystemdUnit(): try: units_enabled.append(unit) if also not in units_enabled: - SystemdUnit(self.root, also).enable(units_enabled) + SystemdUnit(self.root, also, self.unit_type).enable(units_enabled) except SystemdUnitNotFoundError as e: sys.exit("Error: Systemctl also enable issue with %s (%s)" % (service, e.unit)) except KeyError: pass - systemdir = self.root / SYSCONFDIR / "systemd" / "system" + systemdir = self.root / SYSCONFDIR / "systemd" / self.unit_type target = ROOT / path.relative_to(self.root) try: for dest in config.get('Install', 'Alias'): @@ -268,15 +269,15 @@ class SystemdUnit(): pass def mask(self): - systemdir = self.root / SYSCONFDIR / "systemd" / "system" + systemdir = self.root / SYSCONFDIR / "systemd" / self.unit_type add_link(systemdir / self.unit, "/dev/null") -def collect_services(root): +def collect_services(root, unit_type): """Collect list of service files""" services = set() for location in locations: - paths = (root / location / "system").glob("*") + paths = (root / location / unit_type).glob("*") for path in paths: if path.is_dir(): continue @@ -285,16 +286,16 @@ def collect_services(root): return services -def preset_all(root): - presets = Presets('system-preset', root) - services = collect_services(root) +def preset_all(root, unit_type): + presets = Presets('{}-preset'.format(unit_type), root) + services = collect_services(root, unit_type) for service in services: state = presets.state(service) if state == "enable" or state is None: try: - SystemdUnit(root, service).enable() + SystemdUnit(root, service, unit_type).enable() except SystemdUnitNotFoundError: sys.exit("Error: Systemctl preset_all issue in %s" % service) @@ -320,6 +321,7 @@ def main(): parser.add_argument('--preset-mode', choices=['full', 'enable-only', 'disable-only'], default='full') + parser.add_argument('--global', dest="opt_global", action="store_true", default=False) args = parser.parse_args() @@ -336,16 +338,18 @@ def main(): parser.print_help() return 0 + unit_type = "user" if args.opt_global else "system" + if command == "mask": for service in args.service: try: - SystemdUnit(root, service).mask() + SystemdUnit(root, service, unit_type).mask() except SystemdUnitNotFoundError as e: sys.exit("Error: Systemctl main mask issue in %s (%s)" % (service, e.unit)) elif command == "enable": for service in args.service: try: - SystemdUnit(root, service).enable() + SystemdUnit(root, service, unit_type).enable() except SystemdUnitNotFoundError as e: sys.exit("Error: Systemctl main enable issue in %s (%s)" % (service, e.unit)) elif command == "preset-all": @@ -353,7 +357,7 @@ def main(): sys.exit("Too many arguments.") if args.preset_mode != "enable-only": sys.exit("Only enable-only is supported as preset-mode.") - preset_all(root) + preset_all(root, unit_type) else: raise RuntimeError() From patchwork Mon Jan 20 12:46:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55840 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD793C3DA4A for ; Mon, 20 Jan 2025 14:00:13 +0000 (UTC) Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by mx.groups.io with SMTP id smtpd.web10.35798.1737377273547285471 for ; Mon, 20 Jan 2025 04:47:53 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cwWIvQH6; spf=pass (domain: gmail.com, ip: 209.85.167.43, mailfrom: arturkow2000@gmail.com) Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-54287a3ba3cso5051660e87.0 for ; Mon, 20 Jan 2025 04:47:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737377271; x=1737982071; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qGu4ucmyWPGfXRzbhvD9k9ipOAIM2q4CXLJIiUoqCGs=; b=cwWIvQH6zGPaIaGZUEVcl8coK08ihAJuXOM74MfL9L5frr5Q1L1OraGguSoGv1oZBm /RMpbwh8PIFdDZEjSZH6FSlCBPm95h1sQHlM0N9Zsh7hHKh5ofWAjLw4ZICOPw4bgtR9 pmwPC11cwOer4QHOk64I7euWou+tvrLujoa6y/G31y0fWL3k/ccTTcZuWQlgYTrKRFeY LJRHLA+1OHjKO9/5bJtGy90tE6d/v8x1pNN6fnJC0B3J501hN4u1dLd6m+UokMSn1Zt9 MmrrrqJGeT6FMzx+9ygUAxdjqsbO9qRTbl8HOOpjLt/ClrlMdocN/wwFAUgmTrTrXUXc y05Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737377271; x=1737982071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qGu4ucmyWPGfXRzbhvD9k9ipOAIM2q4CXLJIiUoqCGs=; b=viGwJinu//61mtgZ37nJXi+BqdBnxt3GOF/7+bFdh2MrKottXAbGU9tDP3pPz4TGDA 2ttXgzPG8zfxrpEvabYrNR4Mo2TK8Piun9HUEBmwMhAJw98S+GVI760ywDQPA9dfHKVi 8hAk5DFP7y7tIHTAuHs3q5mN6PPC9JMwMUr5DMi56VTyl2NhWXhNjN9u5MVWd3Z6APL/ 1EtugFm5082Fbn0pgrG6fJ/fflYRkyGbrqDy2wODCBbUO+SxtZklDiBPvAijNuZQ1Nal zRY0FkngPT9cV6NpbMOzof2pXzxoKbLKDCqvGCQbVy14/nhtMf0lqTdeKmZb26P6P1Ph J9cg== X-Gm-Message-State: AOJu0Yw11nJp2IMVbwJ7qgv3sdnenZGZnH7k/eigx6I7HvRCA9js2VIL jR0IMkkNge2Lfs6pzuLUQoDKo/+bf8ZPWxaUeLkId4KwWagdWlhzvK8ZOw== X-Gm-Gg: ASbGncvrk6du4HsVGogdscMqdR2HRkCWt0/UCC2H7ck+Ye6rGngk6HVmwpfHighEIn7 wAbOjgTYk96bAzdkrZMkGyGjCTHhqlMMRjUBPfCEXV4Q12qjcv7GVnEpuPxRqlEv3Z178K4Gm8p ruQ9CHyHgVM5RyW04N0sShKDESnxwhZztu41ouzvlLLTBVOqqKrCeZeqIv7wnWkIRhGTSwJeX5/ Ud8JnTwIIIObOt0LTErOUnEcskMzdouC4SeheFq5uck3TmN/n/OBTNYs4sWjJbMKA9W3S2UQQxu rQ== X-Google-Smtp-Source: AGHT+IHaqrqCGAen6w3brLKcKNrb9/BMqqSLcTwIVJJ7IOlCUFMLB0ecCVTvzMhDkbHo17H+D46zcw== X-Received: by 2002:ac2:4e0d:0:b0:540:20c5:f847 with SMTP id 2adb3069b0e04-5439bfb75afmr4896216e87.22.1737377271079; Mon, 20 Jan 2025 04:47:51 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:23ed:c831:8228:ebaa]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5439af0742csm1307523e87.37.2025.01.20.04.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 04:47:50 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v3 2/8] systemd.bbclass: add ${sysconfdir}/systemd/user to search path Date: Mon, 20 Jan 2025 13:46:00 +0100 Message-ID: <20250120124605.263817-4-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120124605.263817-2-arturkow2000@gmail.com> References: <20250120124605.263817-2-arturkow2000@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 20 Jan 2025 14:00:13 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/210033 We already search for system units ${sysconfdir}/systemd/system but we don't search for user units in corresponding directory under ${sysconfdir}. Keep the behaviour consistent so that both unit types are searched in ${systemd_{system,user}_unitdir} and ${sysconfdir}/systemd/{system,user}. Signed-off-by: Artur Kowalski --- meta/classes-recipe/systemd.bbclass | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index 4b4470b7b3..c167689d2a 100644 --- a/meta/classes-recipe/systemd.bbclass +++ b/meta/classes-recipe/systemd.bbclass @@ -147,7 +147,10 @@ python systemd_populate_packages() { # Check service-files and call systemd_add_files_and_parse for each entry def systemd_check_services(): - searchpaths = [oe.path.join(d.getVar("sysconfdir"), "systemd", "system"),] + searchpaths = [ + oe.path.join(d.getVar("sysconfdir"), "systemd", "system"), + oe.path.join(d.getVar("sysconfdir"), "systemd", "user"), + ] searchpaths.append(d.getVar("systemd_system_unitdir")) searchpaths.append(d.getVar("systemd_user_unitdir")) systemd_packages = d.getVar('SYSTEMD_PACKAGES') From patchwork Mon Jan 20 12:46:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55844 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED71CC0218F for ; Mon, 20 Jan 2025 14:00:13 +0000 (UTC) Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by mx.groups.io with SMTP id smtpd.web11.35715.1737377274222242717 for ; Mon, 20 Jan 2025 04:47:54 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QqNKDdvw; spf=pass (domain: gmail.com, ip: 209.85.167.53, mailfrom: arturkow2000@gmail.com) Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5401c52000fso4263849e87.2 for ; Mon, 20 Jan 2025 04:47:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737377272; x=1737982072; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e7dTj6CJeZyBw1KdAvoV2fYXS6oH4jw2N1nAJElvGwo=; b=QqNKDdvwJzYukWmWdq3Yzpua5kXTMwUzV/qrudCDs9pwv4M2KUm77T2SpWEQ7kYAe3 C2vInxGNhz2KLuq+6beI/9BjbBsDvWrMww+2l7rF5fVLX2k+LsTZ1oxE0hGACX+3gVkW cUHO0l+pX0S74lOcJz7saHHqR+yEXfIavFk8G5uhMZqc7/p+91v4/u+vvE+7wvrFe85B sGYHi/MsSGBIDhrDLwDeBgdbxJK+lhOBFGlsT0L/pGkJsuT18Rn9HV/1AChe+s5hRKWz pvKKD1ylpYujcoesbyOzSXg+JUciEXZCxlcF6OlP75rRo9v93sPMqCK3t5VxrTBV7UcL zQRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737377272; x=1737982072; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e7dTj6CJeZyBw1KdAvoV2fYXS6oH4jw2N1nAJElvGwo=; b=vqdnRWiDJBlf3K5Mwr951qdTjvLnCRHbSyr/FL9F8z8cKsWdhXZsM+/ZLnKg9jsjFQ sCpe/DxcQHeWyoZ8L8bBGN3aQ45Ai+BlB9OEfQ4EkyjGhTckix2e0+QzW3lfZkjr7y+2 i7L/wKlyJxlcl88t6nZKAvw9PSVMgXtBTevh6NmNIeOg3kUuall5U+FBXlSuurKW2WRr 4eCFmZe5eRNygwkq2ua3HT2waIMEvyj64zmIl+1YQ3LlbaizkwfK1ZszfdOyn3AWo6Ek QFql5cJgAuX/LLv7G6DeJ2+gO581NyVyR3xZVFkE0uCKPJvr+g7QJIGvZ3IOFhJGRehu NfsA== X-Gm-Message-State: AOJu0Yyq2jDPF1ZarMIxl1kkP08+HX0FpB2/Q4sDS3GJIs2QWeJy206J kLkQL6VprUAVEc9CM1UvUi5ECTnbEm0vS3Ueq7RgOu+JeRlXpxWNdNP+tQ== X-Gm-Gg: ASbGncvoxonZZqc+r1yinWmjwHIGa8XQ6UR9Xp+oyA4n6aKKw3Cxvb12XXY6PqLjR/K yW4/evA22VGqy3UNJBixCD6pOtYuxE/piXZ36hlqxa8BfU4ee6qyW0c9CYuNCUSb1CNYBdQ2guc B+KlFo227xGdEX5MAeRUIDbpOLPVG33cazg0yplyLNdS4D/45F63cCH9XF9i0C4zvVzKojI4bBi Qjlvc1zTtKcbB01GYPQn3d8FeUTm1inj8uItrdlfycNtKRp76/RYI5Lq3UlX6QwQoLmj/NDBQpq tw== X-Google-Smtp-Source: AGHT+IGEPHa3rR6XoZQMxe7nhl0of54Hlo7NCvD//exwWf7V2cBe3hrsCZvhf9CWemOU6d3bz17XhA== X-Received: by 2002:a05:6512:3e03:b0:541:1c49:26a with SMTP id 2adb3069b0e04-5439c2875fdmr5721177e87.43.1737377271809; Mon, 20 Jan 2025 04:47:51 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:23ed:c831:8228:ebaa]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5439af0742csm1307523e87.37.2025.01.20.04.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 04:47:51 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v3 3/8] systemd.bbclass: factor out service lookup logic into separate function Date: Mon, 20 Jan 2025 13:46:01 +0100 Message-ID: <20250120124605.263817-5-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120124605.263817-2-arturkow2000@gmail.com> References: <20250120124605.263817-2-arturkow2000@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 20 Jan 2025 14:00:13 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/210034 Factor out the logic into systemd_service_path(). This will be needed by following commits to avoid code duplication. Signed-off-by: Artur Kowalski --- meta/classes-recipe/systemd.bbclass | 41 ++++++++++++++++------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index c167689d2a..14fef2d7a6 100644 --- a/meta/classes-recipe/systemd.bbclass +++ b/meta/classes-recipe/systemd.bbclass @@ -68,6 +68,28 @@ systemd_populate_packages[vardeps] += "systemd_prerm systemd_postinst" systemd_populate_packages[vardepsexclude] += "OVERRIDES" +def systemd_service_path(service, searchpaths, d): + path_found = '' + + # Deal with adding, for example, 'ifplugd@eth0.service' from + # 'ifplugd@.service' + base = None + at = service.find('@') + if at != -1: + ext = service.rfind('.') + base = service[:at] + '@' + service[ext:] + + for path in searchpaths: + if os.path.lexists(oe.path.join(d.getVar("D"), path, service)): + path_found = path + break + elif base is not None: + if os.path.exists(oe.path.join(d.getVar("D"), path, base)): + path_found = path + break + + return path_found, base + python systemd_populate_packages() { import re import shlex @@ -158,24 +180,7 @@ python systemd_populate_packages() { # scan for all in SYSTEMD_SERVICE[] for pkg_systemd in systemd_packages.split(): for service in get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd).split(): - path_found = '' - - # Deal with adding, for example, 'ifplugd@eth0.service' from - # 'ifplugd@.service' - base = None - at = service.find('@') - if at != -1: - ext = service.rfind('.') - base = service[:at] + '@' + service[ext:] - - for path in searchpaths: - if os.path.lexists(oe.path.join(d.getVar("D"), path, service)): - path_found = path - break - elif base is not None: - if os.path.exists(oe.path.join(d.getVar("D"), path, base)): - path_found = path - break + path_found, base = systemd_service_path(service, searchpaths, d) if path_found != '': systemd_add_files_and_parse(pkg_systemd, path_found, service) From patchwork Mon Jan 20 12:46:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCD4CC0218C for ; Mon, 20 Jan 2025 14:00:13 +0000 (UTC) Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by mx.groups.io with SMTP id smtpd.web11.35716.1737377276440880970 for ; Mon, 20 Jan 2025 04:47:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YGfsxeJU; spf=pass (domain: gmail.com, ip: 209.85.167.43, mailfrom: arturkow2000@gmail.com) Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-54024aa9febso4474002e87.1 for ; Mon, 20 Jan 2025 04:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737377273; x=1737982073; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gUBZ/MjYIEmyPQEgf5zKWhx1g02PCZraW796fbGupF0=; b=YGfsxeJUkHxpCvJA7OXt/WcN5j83a7+z78me78iZMKb2lPdttilFGmKf2id8ndrW76 ezk+omWpuQk747QDG7DjWNzGaNfLx3tqMI0AfNCSpfQZA3Y8cLdN7hWiKWmti6dGkkvm 4fZHVGPT/51PsUhNjoAjivGtkAqlJaPb0IK1chwj99OxSxzbSrw31PSjKbzYO8YEy2gV g6KFiDrXzuiAJMs433C/Zg64p05uZNuVoKip/HiGro3hXBpV6xIGhRXNiVpW1e6svmhE NHcYgFGgJcYp20gBp2aXSWfRB5TuupUIfp9k/aE/hmxbckr97hF8uIbRJcepp6gvzM/N zEsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737377273; x=1737982073; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gUBZ/MjYIEmyPQEgf5zKWhx1g02PCZraW796fbGupF0=; b=TX4zSsu9jH6daofu1SD6dutE1lvrwK75F6I1Yv9P6M1cjCrCpn+i0+lSJYSD9PilEF ci9TdzzKqzt4ZstAxFCocREDsRE9u225RuWHyDqmSDEQs9Q1DF08WIrZ3cshl+M90E7U PNrfsafke4GCxTaD4sfy3K8Ov7rbBDqBnGLTBPYjqZYpIxcAnjMunFmMAr2ko3R686US KA142FxMM70nDK3oXtEYWiR6W+05PQlhJHLBMeu2IfDd+KTmMeB4fC2ohiWeYcu4+o6U +MEXL3RKbsm72EkQHn1i/CuEn8dBS1+P1/OuYuKMC1DJb7iJTUagDQJQOh2QmjfGqCXn /HNA== X-Gm-Message-State: AOJu0YyN5UVU6s0IumemtJI6vKsqd1IM6qcENp2jw5qhqK2WIwNS58t9 2UVDY31klnnb0ueiYSVE3fFUrj4Kxc0MpXngsaU1y1rNSvbYMiKhmc2P6w== X-Gm-Gg: ASbGncvDrcTkWKxLWkuY8vdrMgWCOD1GqMC/tvy33DZdqx/mttUnaNJrFiHGt+r5Hgu 5OQPXjlOB+glC/nFig+u+dZZ/jZZLaYlD4yOyeaYNYChwNd+j7oT03lv53iWqMWP+Vp6LaeSJNs G2T6Ahf8XphXP1Qgp3SHDb9lmhGrOR5glrTKV2qufBkxJvsHf8pM8hrE+9aKsxwmGkW9xYdaqjr h4Fn1IdpVG4SLnGynocINxKC65zaWysTNbSDMR7jqrj8sbMBr2BbjLRvJxNwRdWJt71tQ66dz3w wA== X-Google-Smtp-Source: AGHT+IEoV/xzsoV45WfgSEGCTf04Uocw+AFIu7AbYwaC26TkItByJC8Q5jAj5AVgAlQui3DcXkI9Ig== X-Received: by 2002:ac2:4142:0:b0:540:2a6e:3e11 with SMTP id 2adb3069b0e04-5439c287d97mr2930160e87.46.1737377272489; Mon, 20 Jan 2025 04:47:52 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:23ed:c831:8228:ebaa]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5439af0742csm1307523e87.37.2025.01.20.04.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 04:47:52 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v3 4/8] systemd.bbclass: introduce systemd_service_searchpaths() Date: Mon, 20 Jan 2025 13:46:02 +0100 Message-ID: <20250120124605.263817-6-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120124605.263817-2-arturkow2000@gmail.com> References: <20250120124605.263817-2-arturkow2000@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 20 Jan 2025 14:00:13 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/210036 systemd_service_searchpaths accepts boolean value indicating whether we are dealing with system or user units and returns search paths accordingly. Previously search path list was created in systemd_check_services() but following commits will introduce additional places. The systemd_service_searchpaths helper function is meant to reduce code duplication. Signed-off-by: Artur Kowalski --- meta/classes-recipe/systemd.bbclass | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index 14fef2d7a6..a3c2c6eb20 100644 --- a/meta/classes-recipe/systemd.bbclass +++ b/meta/classes-recipe/systemd.bbclass @@ -90,6 +90,18 @@ def systemd_service_path(service, searchpaths, d): return path_found, base +def systemd_service_searchpaths(user, d): + if user: + return [ + oe.path.join(d.getVar("sysconfdir"), "systemd", "user"), + d.getVar("systemd_user_unitdir"), + ] + else: + return [ + oe.path.join(d.getVar("sysconfdir"), "systemd", "system"), + d.getVar("systemd_system_unitdir"), + ] + python systemd_populate_packages() { import re import shlex @@ -169,12 +181,9 @@ python systemd_populate_packages() { # Check service-files and call systemd_add_files_and_parse for each entry def systemd_check_services(): - searchpaths = [ - oe.path.join(d.getVar("sysconfdir"), "systemd", "system"), - oe.path.join(d.getVar("sysconfdir"), "systemd", "user"), - ] - searchpaths.append(d.getVar("systemd_system_unitdir")) - searchpaths.append(d.getVar("systemd_user_unitdir")) + searchpaths = systemd_service_searchpaths(False, d) + searchpaths.extend(systemd_service_searchpaths(True, d)) + systemd_packages = d.getVar('SYSTEMD_PACKAGES') # scan for all in SYSTEMD_SERVICE[] From patchwork Mon Jan 20 12:46:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55842 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E39CEC0218D for ; Mon, 20 Jan 2025 14:00:13 +0000 (UTC) Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by mx.groups.io with SMTP id smtpd.web10.35800.1737377275668471958 for ; Mon, 20 Jan 2025 04:47:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Vq6ssb6z; spf=pass (domain: gmail.com, ip: 209.85.167.43, mailfrom: arturkow2000@gmail.com) Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-54298ec925bso5304159e87.3 for ; Mon, 20 Jan 2025 04:47:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737377273; x=1737982073; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1QktOdatgETcXATTGpeMs+Jrot2sQykkxwWyuaI+FY8=; b=Vq6ssb6zzqLYdiroYsYoAyuwHL1ujlpRW+l9Q0dyoobRDBQMl8IH28TFlexqQPlxPV +sT85W5FZgSsF8aH6zl/M4giVIgTxrv4tgoKPgfDxzYUMebaxL4ZXs93AzR/xHSMmOtO nN6+NKP9HCUd2FwzPrCrrN7m231OIkw5BeC5im6oK0+77X/SBBeotUw4izoaINjQ+iB8 eaUWSCjYzMEwmfVV88Q77RyrmngCfmgSrffd4E13UrfNESKJhEKMRtN0TfeZqY9CGRIC Llms4VKoM5gncWvMJzGrQN7T+kFbC6z2T2vzt47RZnojrQlayJYPWceSuZcWqbag/aFg 5SJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737377273; x=1737982073; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1QktOdatgETcXATTGpeMs+Jrot2sQykkxwWyuaI+FY8=; b=HbrcVfD7fdjljyoqsngvgkSNV/c7R/WoCOEJUcfy+IaFqqJZ+p+lVKAfVO2XU9Vt34 uC0ML0CowUzNqHI+21WENbqMF2KyKCzQnQKT19DwJYcqTsAju70qVSYEjcK7wObAdr1L tiyvaDWJqW3yM9NEz/q+DT+xXhJg1yhXyfK8ii4Z3886fewVVvQOwyf3UhS3O+VhXgU1 lVoMZ+DNGrU5LiU43mNXfa7hsz4EVyLsGSCQvFWcDIUvhJPD6459VoG95tYxpKn7nBFB SYNQOFMCfpiyrAvWJd2x1KvCYFHwoIET4pLIPLdq+ev/USZrx6j5aI+6EsUxhRpZMHpj YdZA== X-Gm-Message-State: AOJu0YwzRMlx8/Pi224r4yIk8RA6ZTuXGneCcahcOGy89LKt4Dfvkus1 WF0zOSMPf3/5n0bsYMtKPcCsDjoYwkDTZnCgsDC3Vt5UU4MRRtHEXNwYrg== X-Gm-Gg: ASbGncvRvX+TL4UYHFFhk2yaty5zNq9hCweWhTmu7vSsny4avxltvP/ibrwCdFZX4p9 TwgTaCKLlDQGNIJgrCWHj3HSTMI1e/20ByJnEjbB+O5OPXSuitibFf1CyIKOAEb1Q1LcDH8210M FN9dgeE6nPUVYCOhAlXutcScopg3E+k87loqe/QaAVWt3sX5ZbGE8LzLK5g9uuocVQujVwf6jZQ Ww1aSGzW0Pqsw1pHRHQgWgvGWruq6//kGlNBhvk8TBt7AyGtFkgmuEAPzeHkj7L/ofyoHd/2cm5 Sw== X-Google-Smtp-Source: AGHT+IHtUrQxzAn0bTKDPZ+H7NUW+TFfhkOKrsp/Zdy4NGwbBTA5HqAvPlSns9mch4hUimj7LWq8lQ== X-Received: by 2002:a05:6512:108a:b0:540:1fd6:4e4f with SMTP id 2adb3069b0e04-5439c246c5fmr4470910e87.22.1737377273202; Mon, 20 Jan 2025 04:47:53 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:23ed:c831:8228:ebaa]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5439af0742csm1307523e87.37.2025.01.20.04.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 04:47:52 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v3 5/8] systemd.bbclass: properly handle user units in systemd_create_presets Date: Mon, 20 Jan 2025 13:46:03 +0100 Message-ID: <20250120124605.263817-7-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120124605.263817-2-arturkow2000@gmail.com> References: <20250120124605.263817-2-arturkow2000@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 20 Jan 2025 14:00:13 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/210035 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 --- 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() From patchwork Mon Jan 20 12:46:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55843 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED684C0218B for ; Mon, 20 Jan 2025 14:00:13 +0000 (UTC) Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by mx.groups.io with SMTP id smtpd.web11.35717.1737377276758865286 for ; Mon, 20 Jan 2025 04:47:57 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VIUHBYsy; spf=pass (domain: gmail.com, ip: 209.85.167.50, mailfrom: arturkow2000@gmail.com) Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-53f22fd6887so4476770e87.2 for ; Mon, 20 Jan 2025 04:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737377274; x=1737982074; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H1ucR1gqPpkWvG+zJIJUrWmc+irEnCKSt3B+CiYAK+o=; b=VIUHBYsydhzKz2M6yNrVqvlj/KM+hzE5Ry2+2un2hZUw6fJXdAOUVBIrGReVX8Gr7j igz0HuVoulLJS2gfzoN6Mo9le+XjmD88pn6zFmgH7y+JZ48mfT6rNvTVveeTc8BTPNAs TUTD6vM8H0pSvF59aMgNo/lrDKPmzvRF1D5+0louOrB7j+jXnpjeSJjH8aIqsOcHTJ7S WosVyJFltSiqUBu5/reOejOFYFDOw26aCV3I74hLXYr54o5fHLwpsxhv2S11Jl+vV9Q2 0oPu74B+YDvfAV1jew5aQ0ecBI907Rs+1Ip2IuM6zAJWKMZMv84jEk9h/54XXlz804vf aVwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737377274; x=1737982074; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H1ucR1gqPpkWvG+zJIJUrWmc+irEnCKSt3B+CiYAK+o=; b=sKbd0ZFn2KG0rc1oRmJnXWloNZVVH8VNgbYTrW6LeB+g/2rGTeqCjSSsTqySS2stGQ XQYoCU7FphS5a9OIz1Z7XfqsdlBXogp9ox8jwNtlYDZ7R01k6Hnm/zwqgxlpiJIvZMqU ID5IQduoK28jPCEeV7ETyMVWzykXxHyAIFPx9dKC09R9Krj83hb9Rd/gSjI/iIlcQtRU Urort5Y1TCQOkK5p4qRp1ng6VmD+h5NNcCQODqQBAs1ils09BALZRPA6nlBn5oca5B07 Ht/KGcvnCauB7zxi0l+XAnWpneNqZ4l6aXezVy8B5jdydts+79zY0QRaRpFexY91HxiS 3H+Q== X-Gm-Message-State: AOJu0YxCuK+XYY5RblibMqdDkIlpKHnaCujVfO9aCDGGLy4vPjrkEBQh gBriQxdsxJfy88aArIK2I/YMuty0v1aiGUiCNNicEiN8ZcNuv1PfPZ09Uw== X-Gm-Gg: ASbGncuwgdHzhD3fQu67eWcgpr0hxsSvoYtmA30Of/i/EAE8PPtrtZLVWxqygSOCYmT 9WsKYh/aWb/eGMkZaWP64UHyUJMo4zyg8RJIjSP1vZdbtaFeNYzKsNxGKay2BsvzYYbfAxQj15S NHG1EPuXOBQUmvaVpgHrpI6+e+paaUpL92asajD30chxpY/WilpE3KxShWEJFjcvLPFPtgkQGfn x2H2oPM82dXvTe2UR+STOQ8VZhiuSPufOXklvuUlxR/jNi1ZP8kJelD3S54yyfM0IymR2YEgB5g 9Q== X-Google-Smtp-Source: AGHT+IEeZ0+FS5MIVO2f8gr469LCkjnwKF2pcLoVbqfauyGdwPpnQAm4ElnkpviU3DAgkRfqjb2BNg== X-Received: by 2002:ac2:4e0e:0:b0:53e:2f9d:6a73 with SMTP id 2adb3069b0e04-5439c1c60e7mr4988004e87.0.1737377273859; Mon, 20 Jan 2025 04:47:53 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:23ed:c831:8228:ebaa]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5439af0742csm1307523e87.37.2025.01.20.04.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 04:47:53 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v3 6/8] systemd.bbclass: update postinst and prerm hooks Date: Mon, 20 Jan 2025 13:46:04 +0100 Message-ID: <20250120124605.263817-8-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120124605.263817-2-arturkow2000@gmail.com> References: <20250120124605.263817-2-arturkow2000@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 20 Jan 2025 14:00:13 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/210037 Since SYSTEMD_SERVICE_ESCAPED may contain both system and user services we need to filter out user services in call to systemctl. Introduce helper systemd_filter_services() which takes space-separated list of services and returns services of requested type. Signed-off-by: Artur Kowalski --- meta/classes-recipe/systemd.bbclass | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index 592f15a4b7..177ee5d974 100644 --- a/meta/classes-recipe/systemd.bbclass +++ b/meta/classes-recipe/systemd.bbclass @@ -37,17 +37,19 @@ if systemctl >/dev/null 2>/dev/null; then fi if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then - for service in ${SYSTEMD_SERVICE_ESCAPED}; do + for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}; do systemctl ${OPTS} enable "$service" done fi if [ -z "$D" ]; then systemctl daemon-reload - systemctl preset ${SYSTEMD_SERVICE_ESCAPED} + [ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}" ] && \ + systemctl preset ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)} if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then - systemctl --no-block restart ${SYSTEMD_SERVICE_ESCAPED} + [ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}" ] && \ + systemctl --no-block restart ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)} fi fi fi @@ -56,9 +58,10 @@ fi systemd_prerm() { if systemctl >/dev/null 2>/dev/null; then if [ -z "$D" ]; then - systemctl stop ${SYSTEMD_SERVICE_ESCAPED} - - systemctl disable ${SYSTEMD_SERVICE_ESCAPED} + if [ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}" ]; then + systemctl stop ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)} + systemctl disable ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)} + fi fi fi } From patchwork Mon Jan 20 12:46:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D40A7C02182 for ; Mon, 20 Jan 2025 14:00:13 +0000 (UTC) Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by mx.groups.io with SMTP id smtpd.web11.35718.1737377277991160132 for ; Mon, 20 Jan 2025 04:47:58 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JC5X+cZQ; spf=pass (domain: gmail.com, ip: 209.85.167.46, mailfrom: arturkow2000@gmail.com) Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5401c68b89eso4208208e87.0 for ; Mon, 20 Jan 2025 04:47:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737377276; x=1737982076; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F7QnPFsnP9g0G5EXoCQogSYW37osmoAxcLXDwzXJkfU=; b=JC5X+cZQu+nyvuU1nRag1U5gNRr4JABE6s9qqj/IMR6NGL42yUaDH8jvVWyOUUvzjY n/1WAmSs4Zw9Xfgx1mTJ0+v7P045pdEgXmXhj3kE8Gv0fAT6+NMsgdEXuJZC7cU+uaFM gq6MpkdGVGaaNvlDNOThI5Dg9RjH8RbbJ7t0MlbYyrRLIPRtniX4o/GyGuUtNW/ox4QB Ki8g5wqfksNZE075np8ium9X11AvMlxG9nIjwvHjkFn4B3e8FOJtE+fGvqn0g/cCgmR2 1rREAKhA6lfaXS8Sv7Q9mnztPAVakMCIZVpbGIOjY6PHgG+tNOi5hrxFSuFKGIBvXHN6 phRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737377276; x=1737982076; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F7QnPFsnP9g0G5EXoCQogSYW37osmoAxcLXDwzXJkfU=; b=gWbnyPD2rW2DhbA1QZcWahTmx6wagVWOjj/eUFbdF9eLCMzKIe6WBca/RM7qtA6GLq /SSzGNOGZyHxCCt3viEAHsz9R68L53SfqSVeVpDVbDS66VeAh93tiB5y/XaPCN3JBk1A IfxOQB0ARbhjZlxpYRKgZT9KsvdKFOUO2a3QUO9dLwrqyPVHHpqwxd9EP4TaIbugDh0T p1aBlXOHi7zxjQnG/y7fNTd8LAAen+lgZ4xbNbsEGzzsE8TKViyndLolRyfdrqhKBLpN sqZMp01YIHxxQY3xLIGc6Lj4k+Mb7p03oMf9ud4bpY5emKms4/nn5cz4roEZpxJzgmiD eyug== X-Gm-Message-State: AOJu0Yx0n64EZbfngPR12tccDN4dhFzSvmCKbkHOWh4IZBaFA8qswtUT Kc5e2EJJmoLiaUTKiyPhlLzcsS3PokEUFdDUuDLLwVDEFbN6hhR36QoQhw== X-Gm-Gg: ASbGncsqrRdwYOp777TM5qZr22qc3AYx8BGO8S+eQIjZ2ATA9hOq/wy40pcqMT7+r78 sLYFFrs3KrrpaUNFZxJhFzbT5RPRFA+b1fUI8qtXkdrckK/efLKxskYT3zzv6OWaHLMm/TtPtsW JlGTengNqk7D7nfvi7xwM8cm/0f2jRz0JL6fNqlsmnVdF26HHJZ9Eud+q1QaEZ4KOlaQOINRFNS tABOOeX1EOXBQ2wjJ9cQtlTyJHqCIDD9XCNZDQXSLoGKjLkrSKV8agecl4uIXCPDvNLgst+n24+ mg== X-Google-Smtp-Source: AGHT+IHyr1bd6U0SG6qg9ryVGBwPIlb7YcWHMx78ZAwmWn84gL4z1xbhtdoi0VofKKJ/VLmwLIkJPg== X-Received: by 2002:ac2:428d:0:b0:542:297f:663d with SMTP id 2adb3069b0e04-5439bfb752bmr3549053e87.23.1737377275579; Mon, 20 Jan 2025 04:47:55 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:23ed:c831:8228:ebaa]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5439af0742csm1307523e87.37.2025.01.20.04.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 04:47:54 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v3 7/8] systemd.bbclass: support user units in postinst and prerm hooks Date: Mon, 20 Jan 2025 13:46:05 +0100 Message-ID: <20250120124605.263817-9-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120124605.263817-2-arturkow2000@gmail.com> References: <20250120124605.263817-2-arturkow2000@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 20 Jan 2025 14:00:13 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/210038 Handle user units in a manner similar to system units where possible. Not everything is supported by systemd, but systemd limitations only affect runtime package management - during update user services are not reloaded/restart and each user must re-login or manually restart services. Signed-off-by: Artur Kowalski --- meta/classes-recipe/systemd.bbclass | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index 177ee5d974..4c9f51d33d 100644 --- a/meta/classes-recipe/systemd.bbclass +++ b/meta/classes-recipe/systemd.bbclass @@ -40,14 +40,24 @@ if systemctl >/dev/null 2>/dev/null; then for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}; do systemctl ${OPTS} enable "$service" done + + for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}; do + systemctl --global ${OPTS} enable "$service" + done fi if [ -z "$D" ]; then + # Reload only system service manager + # --global for daemon-reload is not supported: https://github.com/systemd/systemd/issues/19284 systemctl daemon-reload [ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}" ] && \ systemctl preset ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)} + [ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}" ] && \ + systemctl --global preset ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)} + if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then + # --global flag for restart is not supported by systemd (see above) [ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}" ] && \ systemctl --no-block restart ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)} fi @@ -62,6 +72,10 @@ if systemctl >/dev/null 2>/dev/null; then systemctl stop ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)} systemctl disable ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)} fi + + # same as above, --global flag is not supported for stop so do disable only + [ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}" ] && \ + systemctl --global disable ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)} fi fi } @@ -111,6 +125,9 @@ def systemd_service_exists(service, user, d): return path != '' +def systemd_filter_services(services, user, d): + return ' '.join(service for service in services.split() if systemd_service_exists(service, user, d)) + python systemd_populate_packages() { import re import shlex From patchwork Mon Jan 20 12:46:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55838 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0868C02181 for ; Mon, 20 Jan 2025 14:00:13 +0000 (UTC) Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by mx.groups.io with SMTP id smtpd.web10.35803.1737377278555069536 for ; Mon, 20 Jan 2025 04:47:58 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CI4jylna; spf=pass (domain: gmail.com, ip: 209.85.167.54, mailfrom: arturkow2000@gmail.com) Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5401bd6cdb7so4253884e87.2 for ; Mon, 20 Jan 2025 04:47:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737377276; x=1737982076; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8u7xQrgGV4VdA/n24Uhxjr8Uhud/VRgVrssrEPXv3dw=; b=CI4jylnaCna3ZBG/zoejdn1EdgNgh6Eco9L04/qprqFOStTfIzCVG4f2fwc5n8UfJK Gh1uEuSAMEbU/ER0uEWfFdpBmzWaxH5X8HEcHN/EVeA3RUcL98WWJbNmILFKSd2cG0zj 91cuQqQ4W2ll012cGXnMLkppSOJGC4D2RjJngVKlupyYA1ojUfD9RKBxfXHW40n6ge72 mpaKS2MKnS5ToTLNackIEPzP4I1eviKZhzkkDlOqKNJVT2WS4rqOcDyXoSlOksxqW+GD t3O89Cvwow19ZoZo+unOCjjQy5l7j0tYvJetM/xVRBiyqhiR3nHu2+IMfwh6kGBx3keX xD7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737377276; x=1737982076; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8u7xQrgGV4VdA/n24Uhxjr8Uhud/VRgVrssrEPXv3dw=; b=GnnqY+KX1aRiKT/4kL7sE48g5ubIQ4JI/JXzYpJtDkHKIrW/LO9k66XO0N+KVbfb+Y b7jNCIdZxAUHt/wxfHvEvclofnpzHZ+JlKK8BO2Hi7zN6eEtyYyMji92jw9ivXXJ8hb8 oSqP67spzGmPek6n4+qjcl+3C94z0BxeEp1mc7ZmzcfrM+na64dh0HmJB/mEPvZ5zRZv GSeKuSSqeTuKnpSV79Y+MR7NY2QpFN/g+FzH3VIZcSkKpoBgHr9iR7KjfT8+gcIF9FiL jxqvwEKE+4g2PcASbd1+L5CMMjY8m8x+BysjYnNS9thfkZgtJcZDZeW5r2rmSzyFfVbr ardQ== X-Gm-Message-State: AOJu0YzVONH3a42Q2ha9EftXLU4E99dwW/jb/8zkJ5RKxLvr0Gv0Lypm FsrHM1JqMqELmw7kFRy1Z7MkxxUwZhgAr86R1xIaieuUhCHwwgJJpSASHA== X-Gm-Gg: ASbGncuDSEbXpYEtWFHms69ZZ1UhIrvLaXIWWwqrak9gYrZ++sITJxDSPjDoRD2tOPc 0vmQ22U5HsRyZZXn8ZXDmSth8bbnRLzjqEIrO75wuD3GqCYednROMYwtf5C8LwRST10s+KmdJKw 0gQgdhkOA/ODP1z2uvfoqfs06MpAd5h4LlcfGxnFrR4mf9g7w0WPPbdn5gV0CwbIbE+gqDmNd5f KXM1s7CMfhpq3oLVyM+I266/1ABgOXjXwXKZPC5ldxqWY67Wt8uRXWsYTERyiGB0p/R575SUBLP Ow== X-Google-Smtp-Source: AGHT+IHvHcz4OIAH60WUaRqqp58iY6ZiZNisauHF7FMpNRd7rb9QxaIxLvNOAbNP2Onwu8NLrbyA2A== X-Received: by 2002:a05:6512:159b:b0:540:358e:36b9 with SMTP id 2adb3069b0e04-5439c2807e3mr4582485e87.45.1737377276237; Mon, 20 Jan 2025 04:47:56 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:23ed:c831:8228:ebaa]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5439af0742csm1307523e87.37.2025.01.20.04.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 04:47:55 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v3 8/8] image.bbclass: enable systemd user services Date: Mon, 20 Jan 2025 13:46:06 +0100 Message-ID: <20250120124605.263817-10-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120124605.263817-2-arturkow2000@gmail.com> References: <20250120124605.263817-2-arturkow2000@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 20 Jan 2025 14:00:13 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/210039 Run systemctl preset-all with --global flag so user unit's are enabled the same way system units are. Signed-off-by: Artur Kowalski --- meta/classes-recipe/image.bbclass | 1 + 1 file changed, 1 insertion(+) diff --git a/meta/classes-recipe/image.bbclass b/meta/classes-recipe/image.bbclass index 84a2017eb5..f08818db03 100644 --- a/meta/classes-recipe/image.bbclass +++ b/meta/classes-recipe/image.bbclass @@ -702,6 +702,7 @@ reproducible_final_image_task () { systemd_preset_all () { if [ -e ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; then systemctl --root="${IMAGE_ROOTFS}" --preset-mode=enable-only preset-all + systemctl --root="${IMAGE_ROOTFS}" --global --preset-mode=enable-only preset-all fi }