From patchwork Tue Jan 14 12:26:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55520 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 30BCFC02183 for ; Tue, 14 Jan 2025 12:50:45 +0000 (UTC) Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by mx.groups.io with SMTP id smtpd.web11.43509.1736858058324793415 for ; Tue, 14 Jan 2025 04:34:18 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ImnCBxuX; spf=pass (domain: gmail.com, ip: 209.85.208.181, mailfrom: arturkow2000@gmail.com) Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-304d760f118so39491491fa.0 for ; Tue, 14 Jan 2025 04:34:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736858056; x=1737462856; 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=Ur4d+aFaZZJr0I+jUqZrGr0cBru0FNWuXjKdEAH8avs=; b=ImnCBxuXWbaRQLpHgYVlEwWUrTa0AcnB9F5HC+V2A49kPLskprZFtzjuwTh0yq6HnI 6t+G+usbr+jjU4Kq3rCWEt2VYRiG+RNVyR6l8QYHTFx++bT58DVexxzbDqwtqlCB0yVK iC0YIgIMpnbkFEGAuj2/nl1ftVmXsOdHr11VDBiC4CYXsTo23noD4u5y71bdzOc0WJza 4GXNVhHSxHdBOmPlrAICHKv5W6jqN5ROqALIPvUizX5FZChMUUYABvbwJaZpfqlTkKzy f0NaZLPsZOyQiWXXXQUvBbJ0rohEaPvioePKr0eMmAX9Qa30v1px2jTdDhwo3tY+86KK PpBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736858056; x=1737462856; 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=Ur4d+aFaZZJr0I+jUqZrGr0cBru0FNWuXjKdEAH8avs=; b=cJrgxcQn39MQZmnqtIcMFxPTUsusOkPg6iyBTwTD8UVDY+P1Nh+Ku+XwyRiY567QFD KlTOJevdlX+UNth/10O4ikb07h5HwzvdeC0wiJpUZjyR9qHXoQuPgOqYhtXgnrwoSZxX V58gmcOIX4qU7qtkhUrSI0lN7SfyG7yFZ8bihyf1jda7MXuWbT2BB52eQNTHZnWUT9VL vy/Uw8sx/qOwMuoh7kY5NlDl6Jy6/bd8lpo1kzIYj6Z4+pEbBDokIwU4WY0JzNZTGKeP dj7hS0eFpyrDWAcJnrKWX0OFgo5o6xcH58YPrffyIQq6YwuYkhcPu3Q57dLBbrkWsIo1 ruhQ== X-Gm-Message-State: AOJu0YwnfvA0k7m+Ka1glOl3MOVg6rkfSXwHYyYH4znU+u2vsk9nbeik aNunJDbvQb5lrET/XOgHK/9BfbusmEAui8RakwN8jg7BxgJxCACWdR1NNP3d X-Gm-Gg: ASbGnctPlZeYMZ9nCzXEnFAoivEni4fztYECFY4rWYmX8BJHU6CuVHMsjsTwvt7uWTz I8YX0tC/5ib4WBGWauot+lB28YlmU+wP+JjGqwcS5aVphiZP0+J7pwgg0ImUXRmGLu0ZrY9Cw+L lHy1C6dxxv6tVzkkSx1dEZ+nSdECkgwECN8f3XJ99fK43ev6db7AhasbpT33Qn2/LQGrixusc66 59eVW1MFubKW/0rM1v5lmw8qYjlnK8IqsAKm3QsP62Pbd46DfFCkjdOrqDUCAHd X-Google-Smtp-Source: AGHT+IHiLOh8BfavONDshyp8FqntNcYG/2yIFazHHxdDVam3w/WO6T3TwWbS9IUbPwmTpdErqh4s9g== X-Received: by 2002:a2e:b8c7:0:b0:300:7f87:a6a with SMTP id 38308e7fff4ca-305f45315a0mr73508071fa.7.1736858055694; Tue, 14 Jan 2025 04:34:15 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:86d6:2e13:1a85:5192]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec4d6sm17230521fa.111.2025.01.14.04.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 04:34:15 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v2 1/8] systemd-systemctl: add support for --global flag Date: Tue, 14 Jan 2025 13:26:09 +0100 Message-ID: <20250114122613.3046925-5-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114122613.3046925-4-arturkow2000@gmail.com> References: <20250114122613.3046925-4-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 ; Tue, 14 Jan 2025 12:50:45 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/209793 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..9b8fe81459 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="glob", 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.glob 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 Tue Jan 14 12:26:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55522 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 50858C0218A for ; Tue, 14 Jan 2025 12:50:45 +0000 (UTC) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by mx.groups.io with SMTP id smtpd.web11.43510.1736858059313844004 for ; Tue, 14 Jan 2025 04:34:19 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XyjB7VRu; spf=pass (domain: gmail.com, ip: 209.85.208.182, mailfrom: arturkow2000@gmail.com) Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-3003d7ca01cso49862061fa.0 for ; Tue, 14 Jan 2025 04:34:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736858057; x=1737462857; 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=yPIvf1yRFfIf+36z2kyn1Vm43EA/pFfujYK/oivpVMs=; b=XyjB7VRuHPMti6x/mf1lKni1tLXQGebJRsmATol3OTZPsuyry4Oxl9N22X9WvUWSAv +oeq9koIC0ozlmJsLlO36GhZJF0xp0wCXKiUuNsNIflcj9rP1gq39UHU2mnueZqi/6Dw gotXTTbdEWh5GghEJiLcxRGPaaaLC4qquKRnas29YAJEvoM2+PFfnR89vw0hLUznkYfR ZaWsZ5RldQTGkJRTo6/0gdGaN7BYPdLD9JRLUb941Ulm1MlMbed6QJeXJ5azGKFlhBO5 5/bWd0sfVDOOkXgNGJ24es2Ej1RkYaDRktoXRl2C9o7GRw81SaA9yVOePv0W3XKlZ1Za cv6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736858057; x=1737462857; 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=yPIvf1yRFfIf+36z2kyn1Vm43EA/pFfujYK/oivpVMs=; b=bLQTx2vfOmRv8PiWzy/o62BjsQAMyS6DZ5ibQqSfG6TqVwUBcqtk5sXXXR6Lu/U3Rb vTy4se1o4IGfuJ5/ZGvtgWRE4zR5PRZosOAgVK4xpMMBYH5Y03nqwvn4kXPU8jWxKlM9 sMKv7mUDzqw5g4pKJs1vmRwDGY/VC2mdO/uDBeKPKRnRlyJ2jCSlM8//szeW27emBI8/ llHu37vBFm4iBg0Yb60BI6e8u0aV+u/0yD7nPmFUolES94YvqB1l1pRd+ulx1mwxmfsq WJhgVQARElnjdHHEVJC1BQslctNSgTm//q4twS/iKqy8bRBEK/RqI97E0vgfIPHFLQ2Y Y8pw== X-Gm-Message-State: AOJu0YwxP6wd6K50cqSbYyx9i+2Zltu81qqD2yz82yf5vsNuXAPxAKrc RaHBnwL+4wmHjGU8TDy0GciTQsjFFEZbIzcbvSpoXob9azP4SL+/OV/JVw== X-Gm-Gg: ASbGncvfrOM2w7vNOeT8IhAiSQwyXIhXvfY3EvsZPkbP1Goft7NNQhaQAui0/lPHO4w 2mO5xiKBezFsyLRh229oghZ50OpU1+/h1zXQAEzdB8SPkE9MC6bltSe0vHoMHfl0+kLwRE6bs8U Ond+Xl2ZiVMUfBulYd9G/emzzYvsaSTV/l0nxpzy1vU9Zh16S6vjut2+58ClTqNj6+YzqDAhRVi 0bQa8VCsEv2UcX70EwkA9z0NkumM25tNp/kOv0ws1JgH/TCYls4sn+XMfcy4vVG X-Google-Smtp-Source: AGHT+IHTqVTTiFCQgZdkd+oP3ke4M4tyQf2gaZmT9zmbY8gRlgqIgecuIbIlop6ncuHHbxcTHvgKcg== X-Received: by 2002:a05:651c:210b:b0:306:10d6:28ab with SMTP id 38308e7fff4ca-30610d62b3emr35731151fa.5.1736858056589; Tue, 14 Jan 2025 04:34:16 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:86d6:2e13:1a85:5192]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec4d6sm17230521fa.111.2025.01.14.04.34.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 04:34:16 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v2 2/8] systemd.bbclass: add ${sysconfdir}/systemd/user to search path Date: Tue, 14 Jan 2025 13:26:10 +0100 Message-ID: <20250114122613.3046925-6-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114122613.3046925-4-arturkow2000@gmail.com> References: <20250114122613.3046925-4-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 ; Tue, 14 Jan 2025 12:50:45 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/209794 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 Tue Jan 14 12:26:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55524 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 4ECCAC02189 for ; Tue, 14 Jan 2025 12:50:45 +0000 (UTC) Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) by mx.groups.io with SMTP id smtpd.web10.43086.1736858060489111405 for ; Tue, 14 Jan 2025 04:34:20 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NlsBGBtI; spf=pass (domain: gmail.com, ip: 209.85.208.170, mailfrom: arturkow2000@gmail.com) Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-30227c56b11so48995501fa.3 for ; Tue, 14 Jan 2025 04:34:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736858058; x=1737462858; 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=pcJRygFYCbzJG2rQ1n3UEsxd1nm965Vj9vkbXqgqnsE=; b=NlsBGBtI5I3gmzsDrOy3OwsF6ib77tEvLN5SgS9RVRL+6Q7JPT+GPx1LnrrYA8UaWC wJfm3IsAp9+lN1Ai6b3KI0aZD52/iTOhAbLT/o+wCCJhKIcX7Ta0JQpr/wXX4cmw5Yrd n8okFPhav3e9MGvkZ1Xz3Hyhytsn0Nn+kESQshbB+oExQKubgKZAgnqdMLiqVZtDAL9T ryAKFbxEH8+7Yxs31vWJIr1m6n8XB2xhmZNz4WQBkaueMraBa1SHgs+UJTU+8uJP8fU6 OUWYG1xq1ZRaq5e45niyvcchWMLzhB7vfSPukD9xkuuSqk2cKtxvQLIU5xI7kD7M7NdH ub9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736858058; x=1737462858; 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=pcJRygFYCbzJG2rQ1n3UEsxd1nm965Vj9vkbXqgqnsE=; b=RjuMj2COaHU+EN/RjH0Z8XFgtYqu1tF8dm+PurXZMXibsYa9ScuQXBFbKprPpCtHsn w8ZO8tL6AGoKGQ1PUDhw7nGEAz6xaTp8SWdxZRy7F+pnDNCLj1Oz8mahWXuQvhkZAi/R 0b4la//BYzgOUG5zpcA/bzeLbw9xexEcLR1CdSCfjNgOCZXylnDPz4siAZG8/x0GEsYM AmRT8E+puV0CfO0PNGIu3XjBbmxe2hPdKyj19p81SDJHFDbIatVEplrMvMLrELaOs2mc A75jJurEThKSPXCyFJMxCqtCbuO6R3JGFXQRPXKDgDfUFRZxOPwnkmROLaIMyO/goZkI 280w== X-Gm-Message-State: AOJu0YzqPFnahcv7HSs8TCZyLNVFNO2yJey4smJKVCEUOAr+gcEK97y6 YXDHUo84rTAHJ+Hkm7jfZP7ysnFlgq4C8fRm4Jt5g7v5K1BuYBG4ZJP5AQ== X-Gm-Gg: ASbGncsF/DZwICOh+TKN6biFxOKwz52K1YfTTAYdpzp8N7ZadGivlO19faNtajTRj0N x+YILgDk/D+/Bti+TWQYpLodu7jciiq0CeJGjF107ljt0skRV6zp5pVQCIJvfkn2P76nfxxGsqT UUUJ+2ajyefOfJ5WGQU6jqWzChqUkdB4Ks0jQyFQvSuoj/G2V/HIlYcgGwyhv+MYSNmUZ6wBidI r+EvaeAqiK1W/0qpTl14WZmTmarjz0qzntkYkx19ChSxQocVzrukemPicq8ll8d X-Google-Smtp-Source: AGHT+IFU1Hhw0RMPYWe49f7Ez9mEinF+qOTNRV9AONEkdXTq46ryXG3iwoGcrT5sDQgiz7XcR3Y7Yw== X-Received: by 2002:a05:651c:2223:b0:302:4115:b69 with SMTP id 38308e7fff4ca-305f452fde1mr81509261fa.8.1736858058093; Tue, 14 Jan 2025 04:34:18 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:86d6:2e13:1a85:5192]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec4d6sm17230521fa.111.2025.01.14.04.34.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 04:34:17 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v2 3/8] systemd.bbclass: factor out service lookup logic into separate function Date: Tue, 14 Jan 2025 13:26:11 +0100 Message-ID: <20250114122613.3046925-7-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114122613.3046925-4-arturkow2000@gmail.com> References: <20250114122613.3046925-4-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 ; Tue, 14 Jan 2025 12:50:45 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/209795 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 Tue Jan 14 12:26:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55521 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 3ED59C3DA4A for ; Tue, 14 Jan 2025 12:50:45 +0000 (UTC) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by mx.groups.io with SMTP id smtpd.web11.43513.1736858062136823036 for ; Tue, 14 Jan 2025 04:34:22 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Uq/7/XvI; spf=pass (domain: gmail.com, ip: 209.85.208.169, mailfrom: arturkow2000@gmail.com) Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-30613802a59so30351211fa.0 for ; Tue, 14 Jan 2025 04:34:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736858060; x=1737462860; 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=gGkYoniNL+WDKzmUuH939EbSlPSgF9FFhsyM1NdmrQA=; b=Uq/7/XvIG/uxKGif47VwaTfmMzNdm+uHdgWD5jzoWmJGnv1DRXlefNJCbejxIf93m9 weUHqod0YZiYJWT7dYt71eeK95vpi2nPkjoulTOozjjU0/0moI5tppRg7L1+5CbVlq01 FnlYODIe1D07NCf/lvxtEkTPEZVaI8DxsscW8+AdjEteIV+e4kqK19Ftt06UnbNrmOft WwzWqwLULJd/RBKYFRYSj+EtL+Wl/ATbQdXmz7/adV9BxqO1x5m0XjWar1QlSUOI2sba ikg/YJBatgU9LceZIsiKvXoyL56pztNLB4JG18yXbwk0OYLLHIjrKjpR1PgJOtqDuTKe 0opw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736858060; x=1737462860; 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=gGkYoniNL+WDKzmUuH939EbSlPSgF9FFhsyM1NdmrQA=; b=aYdDCPpqx8+TDOwyxwwO8iOGGH+rSI8oQkVVkAC5i5BQt2eEqxV4LSsymE0hL2VVfA gMYYdXlvvQig81P43aJaUDndlf2WvZjQr3vAw5huVkZHhyz1C6ZjR80e26dWsRl+uPbq vIkfsdk9VvUQ1uVSLYaB0wYHZHMO5s5oTAcbg69c0VdS9nwcYYgEgPA/NF3sO0gII2uG IQZG5ZAMRxCdhIJ2K0tQYuo/ejykVtb0sA9SPmB7XhNIiHtsrjhb50QNJ3SO+uqScd/+ mZfSWSFlugPxhEqf/oUk5XzUV/oJxkFaHsQr9sGq4SRkEyJ++Lm8N0kH2viDQIbvNdnM /t4g== X-Gm-Message-State: AOJu0YxEcJGHuPZtwROdtvSGdnyfRdRxUvL+I9hwJs7E0YvuVMHexfa9 O8U6cD1YKwDofHrUK10iNHI6EzqCNoYr9EE9uuS0dGnxpRZqukmaNHbZ0Q== X-Gm-Gg: ASbGnctmvYlEzZyJgZ8Gr4ztEMx3dwm7pTzhfDYN4xKquLsQwMR6/7OYthCwgEmZv+X tVSSLzwzzoGOYfoLgHxMsrDKkk2uoFp9jngbXDGwME7IpJV/k1eCjqEc3DMVoE1B53Es2pGrPxP WuF1NZ5DtDGxqS8p0mfR+S/EEbY5IUPTKcv/LHOD2YY5VIAhOtKWX6ZJE7Ny/XaYTvDi02udXgw P94OhVj09MDfOtMgj06MzsuheVef/10lDvQuMHKMK/DlTP/NYOj+8R4pYccRqzL X-Google-Smtp-Source: AGHT+IGuwiSHJztevMFvm/u4rA6mJDlTe+4eLfsWtxUpp4Pi526HCbfqoYJgFAF+l5JNu5RY7D+lPQ== X-Received: by 2002:a2e:a98b:0:b0:300:3de4:ff7f with SMTP id 38308e7fff4ca-305f45300a1mr83788981fa.6.1736858059595; Tue, 14 Jan 2025 04:34:19 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:86d6:2e13:1a85:5192]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec4d6sm17230521fa.111.2025.01.14.04.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 04:34:18 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v2 4/8] systemd.bbclass: introduce systemd_service_searchpaths() Date: Tue, 14 Jan 2025 13:26:12 +0100 Message-ID: <20250114122613.3046925-8-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114122613.3046925-4-arturkow2000@gmail.com> References: <20250114122613.3046925-4-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 ; Tue, 14 Jan 2025 12:50:45 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/209796 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 Tue Jan 14 12:26:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55518 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 3D326C02186 for ; Tue, 14 Jan 2025 12:50:45 +0000 (UTC) Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) by mx.groups.io with SMTP id smtpd.web10.43087.1736858063983296146 for ; Tue, 14 Jan 2025 04:34:24 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=aaJje6dP; spf=pass (domain: gmail.com, ip: 209.85.208.170, mailfrom: arturkow2000@gmail.com) Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-30167f4c1e3so47499271fa.3 for ; Tue, 14 Jan 2025 04:34:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736858061; x=1737462861; 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=EyM/lhGriZkk3C8yfuaMmHJTbeA/ePF/wbk0LZ659Cw=; b=aaJje6dPE7TlIkKj5WV7i2vX0EbWFpLfk2R2G0OM6hd5PqR7kREAf8Gyir6r7qKRix AAyv8Sm5Xy6k5O6dYE8X/2keGf4YgW/DYbagFHjK67uZbQ84KwVT0UrXLF5QW9i2dfMq 5Pjv8Zb6OhrwSLStltauqNqJDDVECAeZr4H4laQ1p/+9DTFnE7RvoYxP9a0ibahuuLB3 YNGk5BYvMTJhkfF5+AcqOc8kTs961ybXtseDkRU2aDJBHzkO4BX6lvpZd9SgiS9NXQgs +nV+fkYAsCP7Bpk9HwdPxuAByaQnG3mVeuHqJoqkBc0pjYsO6C60geroAWnuoDc/A5g9 fbCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736858061; x=1737462861; 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=EyM/lhGriZkk3C8yfuaMmHJTbeA/ePF/wbk0LZ659Cw=; b=A7OT6A/yYq8tWgecscIbh+RYU2SPrU+dAmqnq0/cku9CbOlrvtuZxHYZ/ME8uLOOc4 mc0yg0O4JqZYrbwkvxKInvV/XBTyPYSctHRqGYUo4aunje32kXQzEXjQuYaScVQbH5LV jsY2G5ZPmeU2nyNqLS1Oe5c3kcIxdOHDkG5pZbfUT4a0YXH1TgrkQybphHizTrgqM8B+ MixDbogj/3O+k9P3TrbHhswYhuH4CeMCCuWGw6aC4DqX0pQeAbwyrE9suzMGt1A+2J2Q V+RIMkRV7s91UjlBG/upSLg1F+0SU6fDlbG6feQPb8VwSf4P9R4wcPAzshVWTVVNWUfS O9dw== X-Gm-Message-State: AOJu0Yy8npZeGWGZCPS/Ug7JoeCApykSpFZUGm8n4B5eigrU/UhI+Wbh jTvz7lmVPXFz4ES09ZOF1C7O6UBRBXekyKDFaBV/j+KWQHvCOB6ZL3iqsQ== X-Gm-Gg: ASbGnctuZ+S2z+Q4GYOPRJcucrB2H8z92es3SErFRacJUFhVZjmOR/iarLqldakIi4j bWrYyLRlX18AxcvXb2/PeLPteowLGW2CuPQPAtoh9CI8cOQBYv5UsIo2506z+qgYrgAQxGiCcrs ndCn9oVK1NTuX+LNuv4WWxd9Gh2cfaSGrsUe5B/54l5ohGYcIBWCQ9H5h8X86WDNEGdzBD7DsF5 JUhZr6VjRwcV2BiNpoSBM9gaedOMrULsaBWqAO+xgOge3Fo0yNvDQ+Y/98WYuRc X-Google-Smtp-Source: AGHT+IFIM4nhCiJt+Rh0Bsbp7xBUO+8ipMUcrOpJP76oSufqHko9hgw9XNhwJMsWINtlljZ+jQ5kwA== X-Received: by 2002:a05:651c:897:b0:306:26cf:1305 with SMTP id 38308e7fff4ca-30626cf13b0mr17591101fa.35.1736858061182; Tue, 14 Jan 2025 04:34:21 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:86d6:2e13:1a85:5192]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec4d6sm17230521fa.111.2025.01.14.04.34.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 04:34:20 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v2 5/8] systemd.bbclass: properly handle user units in systemd_create_presets Date: Tue, 14 Jan 2025 13:26:13 +0100 Message-ID: <20250114122613.3046925-9-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114122613.3046925-4-arturkow2000@gmail.com> References: <20250114122613.3046925-4-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 ; Tue, 14 Jan 2025 12:50:45 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/209797 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 Tue Jan 14 12:26:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55519 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 3D3E7C02188 for ; Tue, 14 Jan 2025 12:50:45 +0000 (UTC) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by mx.groups.io with SMTP id smtpd.web11.43514.1736858065987714045 for ; Tue, 14 Jan 2025 04:34:26 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TE8HSubU; spf=pass (domain: gmail.com, ip: 209.85.208.182, mailfrom: arturkow2000@gmail.com) Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-30613037309so27530851fa.3 for ; Tue, 14 Jan 2025 04:34:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736858063; x=1737462863; 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=v82dtYRjhLq6Di2/jE4R5M6bZi8i8cHZBw658/dNwQY=; b=TE8HSubUG4DFTg5ZZrD4rhDjsTPz08ug+n6BbSzOc5F9rr5cSBUVoun/RXqm9th8VW xji+AlYb+5XfIfFfPv2d7DrlftlcRvTmLmJekDtwzlHV1dcfXHJOpTNDEKWuqSwRsjBR unnfJtvDtdPABb5vQhAuNRpUpSarbP1DjxIexP+YK+lxE5sAGdtW8afX4zDzLYk7nzYS MYnBTLp9kK/sGoWxAMrfsp/hoUdFZYHfcZTjMdaQjJQUXmXxsz1YJeJy1BSgBLJp56Cn rfUo5+kv8CLY22F7KyJ6wvBj8Rbd3vj9r5gw/kOCvISlj4DysSz/gcdUTkzdKcx03zCl b/cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736858063; x=1737462863; 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=v82dtYRjhLq6Di2/jE4R5M6bZi8i8cHZBw658/dNwQY=; b=GaR8EY6YCAJmHuvmq1C7oWfCPsEiIQ9F9PIiakiVhPV3ajkOccpTAKZC2yTnQCh9M7 lbYHr8sKZuuWhV5QhGXuP1Pv80zkeoDlTduudybWExvIYe3YtPqk+mxBw6Kq/qWxdM7L KEUbdkX9Q1YloqSsb1BzM5x9Ybk9lSa7GERPwc/I6sl8eX37M+FmZ5BOSHaMX6joCWh/ SkZievb3j5QAIspOyxpW1fFVaBB8IjTZZHKqaUMo8VurEzXG0kUqTGC8k0HuIoMCo5Gn V5LMhSwmGKVpbcxgN6gAmxa908IgOl+DrXb16qQvmFw58uwARegyGzruBxepnGXLEX/n kRFw== X-Gm-Message-State: AOJu0YzEmSSDR2/X+Gcb391yN8BXcXkR09cBWjoL22tl3onWB7c65aX/ B5mwaNwQj/3rri+js5RHjkjuXFj4BVgOscQ6SrKSyQCPOY4w/CLJtBKhmw== X-Gm-Gg: ASbGncvBaVbxMzqJ6rCZNHQn6h9zyXQAPJ1OIRAaHTuLow2GzFrqqeDzeQ5o757TTo0 9TUHHOKDp4PnLw7Xa3vlyST2v7SMLkvcnLHHTu7LaE6ymW0EOCa3yzqNWZdFWQhwM0B7+XyIHzw fY+DkjC2xmQPcjmr3g9US6dQijgcbutuzMpGNiOsmQjyGYzfu/I8OzvbfekSGGpypFO1XSTUJpb Nffk9b9FbHOKubug4MUPYV4nXONGUaXmMWdM6p+kvMpfQ3uQV5sYDIouNzpWbkB X-Google-Smtp-Source: AGHT+IGMcUNUViuhIVkRo572dkB/kQw8GwM/Yi/vqBrf5kV+kZlPMaDCeS1zdG02AI4ByCnMfTRMOQ== X-Received: by 2002:a2e:a583:0:b0:302:26ae:7bcd with SMTP id 38308e7fff4ca-305f45e4104mr87659881fa.23.1736858063414; Tue, 14 Jan 2025 04:34:23 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:86d6:2e13:1a85:5192]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec4d6sm17230521fa.111.2025.01.14.04.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 04:34:22 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v2 6/8] systemd.bbclass: update postinst and prerm hooks Date: Tue, 14 Jan 2025 13:26:14 +0100 Message-ID: <20250114122613.3046925-10-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114122613.3046925-4-arturkow2000@gmail.com> References: <20250114122613.3046925-4-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 ; Tue, 14 Jan 2025 12:50:45 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/209798 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 Tue Jan 14 12:26:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55517 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 2E40FC02185 for ; Tue, 14 Jan 2025 12:50:45 +0000 (UTC) Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by mx.groups.io with SMTP id smtpd.web10.43089.1736858067366709510 for ; Tue, 14 Jan 2025 04:34:27 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EsY80Gsb; spf=pass (domain: gmail.com, ip: 209.85.208.175, mailfrom: arturkow2000@gmail.com) Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-3003d7ca01cso49862991fa.0 for ; Tue, 14 Jan 2025 04:34:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736858064; x=1737462864; 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=dVxtP3mEg1zvLOnnyXlnjDGOSyoXCT1n08lG2cN8FfQ=; b=EsY80Gsb3K/vWI67ZNBNBkCzAZkNa5WYnM5kWOkoewZITl+Zm4b+KgxBSlnV0lOfyk k/gWhfdwtj5FZRDvf99lackExNXiaMhNE0AVi/ikn3zZyXroGiMlcb8lijuZnyRHN/YP CaHAj7/CWC8UbzsqAsshTHsh8NmXrQqZzfi5nRQyuOlq/60z9Y6F9L8SezgdDLdRi78c uLNYEUGAj+xQqjjSPsaWvug+D8qo/iNHjCvf+bIhX7mUkDUfvZ3UvIakBiHsySCurbDh qfxXG9iW9NnjO4BGpu9wApN/u8V4+KXvutq2UgYk819uCMjaCs85Wa+XSZCmm30EKrWg jaVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736858064; x=1737462864; 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=dVxtP3mEg1zvLOnnyXlnjDGOSyoXCT1n08lG2cN8FfQ=; b=KMgbUfxXaaW7uBYwDx2DTi3zmOeADUpZyYn8fp25YAz4sPr3nv0uS5BZpfJ4R4IJNK vCGn3d1AzGEd+b4AUZK1a7ut5w55pGfw7tU7YSSpSI1KLAqdV1rBznJMPPgge93LsJXW QR+52wQE64Wu18z4TB3Kf7fBKFJEcfOJTpCyECyYp4g1y55fLfN4YOo5eU1d4XsILHYr z+rhHBWm+M6GD1vD67m4iLZVZtQ+0+/qAJnERxiSGNjw2GUkA0GyNVpeaXLLEEZ++7ki n/NZDF8N3H7oj7fACHDfkfZyFiNyGS3DLuYGDt9WE22206wI+LOJTvGCvWuv3RSGteK/ MrOg== X-Gm-Message-State: AOJu0YxTnSvSWn2A7Dtgec3S6cHjljJsxkvaV8HZ5t8WJ3c1gmGLI3eo iV8uyfz/mOL5manFv0QJjwM3/0UuPa5YNrL6VLP/Y6fRuZuOrorcEJEFnA== X-Gm-Gg: ASbGncvSg7ROj8Ypio5q9WxNDJ+/zBSDkPYwCBenFmOGISi8//BXJC2TTCYKk5GiFow psLYCv9xf846QbIUrDjZeQRP36/B4fbVZ2smsGeVilO8Kxf9qwjgdNn6sE3BjRXgf3S9LA1EKk8 p3Xqbs9nbyH9XJzN+Fsj0p/O29Eq0zRYDMx0Ye73usHGEmnDkzuQzYh33iMlz7BzHtJ93C75d5M ZtYUHHE6Hnkq/fK5baDedfYqIu62kKOOSesHyHPkrUZVDCOqnNlRt4jpT51CjFT X-Google-Smtp-Source: AGHT+IHUTE4uJbwJ1AgxHkjR7VLmgpWkAKboV3bjjxO8tMhj3DH62zrQWFuNnNS1BTeydaKUymmChw== X-Received: by 2002:a05:651c:a0b:b0:302:40ec:a1b3 with SMTP id 38308e7fff4ca-305f45a0a29mr79469851fa.21.1736858064287; Tue, 14 Jan 2025 04:34:24 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:86d6:2e13:1a85:5192]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec4d6sm17230521fa.111.2025.01.14.04.34.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 04:34:23 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v2 7/8] systemd.bbclass: support user units in postinst and prerm hooks Date: Tue, 14 Jan 2025 13:26:15 +0100 Message-ID: <20250114122613.3046925-11-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114122613.3046925-4-arturkow2000@gmail.com> References: <20250114122613.3046925-4-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 ; Tue, 14 Jan 2025 12:50:45 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/209799 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 Tue Jan 14 12:26:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55523 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 50BA6C0218B for ; Tue, 14 Jan 2025 12:50:45 +0000 (UTC) Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by mx.groups.io with SMTP id smtpd.web10.43090.1736858067719222339 for ; Tue, 14 Jan 2025 04:34:28 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ma8Y9RJd; spf=pass (domain: gmail.com, ip: 209.85.208.180, mailfrom: arturkow2000@gmail.com) Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-3022484d4e4so49770041fa.1 for ; Tue, 14 Jan 2025 04:34:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736858065; x=1737462865; 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=nYi/TTm+1enNtA4IV/T4w0oMOjdGSmQfvoH4tld4LEs=; b=Ma8Y9RJdujZB018Gj9SzgKpT2fTOWG6sQpGXQy8fHUce12SjjHggY47iqoBQDJpJOc fR3yl8mMNcpraFeaIGbDN8byvrqYkPDTgZdgsAOeAUTe8UHg4heaQVHjIGgKip1NVGpp PNu7pdRlCE2QjiRCvcDf109+VFcksjxw/KMHSOWCa6TF/C9vQ9qhoNzsVnY3OVNAbhBn CXRM+SWrf9Qn9Sbx0+rhqA6/PI6IOgRZfoK9ov4l4BwaT83UysddmT4mImTGsh+k4lwc IBDFVvkHwGQjb523G7olMGv22Ud0LpUiyWIqxZfGUKh7k2QjOMfOdAhIFMZ2gTaLF20M lpBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736858065; x=1737462865; 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=nYi/TTm+1enNtA4IV/T4w0oMOjdGSmQfvoH4tld4LEs=; b=OrnbypN9gkYHCs7+RV8cQ3Z7x/DJPzgO0wUBGVqlqe6khS/muTw0UbOrXAhW1LmX6G TWXtFsVTQIeTUTbYii7djg5RvPVQ57IQ/3ctUvJ2F53THC/E6p3K07xz3FJWEOmdOhTu jJmOEcGVIVs1ON2sKLEQKnxBRexHA56SlS20VTQXsjAJgKp5zNXu+KhocWgKmVOymlPM OYFd/LpVOnTRSGX0hknlXCBfd06Lqq7pqOdyzVu/rQLeKRsoL/KYw8WbGOzqFLUyuD+0 2t/PcKs6n7nFEDuPpTnDJEiG7TP8mexugZlhbYQzzAHuXNs/r9H0ahvxXRR6Kytwi3wB Fg6Q== X-Gm-Message-State: AOJu0YzSPxVjRzPmRyFoV4+8KMhWxMV7VWuYmY9mePHKpSRTxrJxzkfJ GdzLdKAgfFOPF6NRwcaf01gilY6Og3crTNfxr/EtA/WRw6LjNfbOsBsh6Q== X-Gm-Gg: ASbGncuLWchuvFxXEgaG3oy5AjuBTTkEEHZwdsp5wc9vWutZJGZYzUnbohrZdmb4tqQ jQf+Jt+9h/aeYigOcve1TEb5zdeggBTkHZysWt1lvcSybjtgXWmJgPR3Pbi4KUJ/SnCMYDdvabH zEafd1XJzwM2b95ykOl+gcPXNp77FD3+CNB0teL3XiQ4J+J26s8JGEuZ6AYx1QNBZrV3oSZYKaw VFrPn49t2oMHqWI1vF5jcj3vrnQSn8PSMTf9eUrJt/T2BQioifUvRNLJU42C//z X-Google-Smtp-Source: AGHT+IH8Ulx1/I+rl3bPdZ/vVmZvPfaPeAWS2Ct9NEfRt6WNzKih+YWuO5/u4tdU8KzuVqktLtUOXA== X-Received: by 2002:a05:651c:556:b0:302:3356:7c55 with SMTP id 38308e7fff4ca-305f454741fmr65881521fa.10.1736858065190; Tue, 14 Jan 2025 04:34:25 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:86d6:2e13:1a85:5192]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1ec4d6sm17230521fa.111.2025.01.14.04.34.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 04:34:24 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH v2 8/8] image.bbclass: enable systemd user services Date: Tue, 14 Jan 2025 13:26:16 +0100 Message-ID: <20250114122613.3046925-12-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114122613.3046925-4-arturkow2000@gmail.com> References: <20250114122613.3046925-4-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 ; Tue, 14 Jan 2025 12:50:45 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/209800 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 }