From patchwork Wed Jul 22 10:14:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himani Ramesh Barde X-Patchwork-Id: 93205 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 5DC38C44532 for ; Wed, 22 Jul 2026 10:36:51 +0000 (UTC) Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.44592.1784715249464739687 for ; Wed, 22 Jul 2026 03:14:09 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@windriver.com header.s=PPS06212021 header.b=ZFtt2OxJ; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: windriver.com, ip: 205.220.166.238, mailfrom: prvs=16634ecc35=himaniramesh.barde@windriver.com) Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66M8wtZF576237 for ; Wed, 22 Jul 2026 03:14:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=cc:content-transfer-encoding:content-type:date:from :in-reply-to:message-id:mime-version:references:subject:to; s= PPS06212021; bh=6BJnIf16s+PXrptZ/TCHuXR7Tm63PIafxaQAC12SyGI=; b= ZFtt2OxJJkjnmDuHDGzr64AYrHRIuNwA7HbAe6LCS7W6oT8UGo1IcUbsvBIW+1LD /t2CouZjtuLjaWLq8kfeYoncg4x2HNnp65F9XIuOeF73vIZyNTXw3JIcK/FpYXFn /Eh6PDHzIQ0njCxL34rTEu9UXGRYcKn080QUHhJnbF4PjMQEwdnDKZRgyJK/+kiE 8dSgQlCyjERTAuJ2vuGaU4xNjxJ0kUJ3RE50ZgExgHPi4IrCnEONpNhMp6c56Gnw z17GuSY/woSt9SsejxP/V5QFE6m1RmYIHf1PyPnUljta6iIC82jHDfGuAFVdJs6K eVjMaWLbDw0zfdpRFu4Dog== Received: from ala-exchng01.corp.ad.wrs.com (ala-exchng01.wrs.com [128.224.246.36]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 4fg4ryqu14-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 22 Jul 2026 03:14:08 -0700 (PDT) Received: from ala-exchng01.corp.ad.wrs.com (10.11.224.121) by ala-exchng01.corp.ad.wrs.com (10.11.224.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.61; Wed, 22 Jul 2026 03:14:08 -0700 Received: from oak-lpgbuild10.wrs.com (10.11.232.110) by ala-exchng01.corp.ad.wrs.com (10.11.224.121) with Microsoft SMTP Server id 15.1.2507.61 via Frontend Transport; Wed, 22 Jul 2026 03:14:08 -0700 From: Himani Ramesh Barde To: CC: , , "Himani Ramesh Barde" Subject: [PATCH v3] systemd.bbclass: fix service enablement for cross-install scenarios Date: Wed, 22 Jul 2026 10:14:08 +0000 Message-ID: <20260722101408.3225399-1-HimaniRamesh.Barde@windriver.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260716061519.765593-1-HimaniRamesh.Barde@windriver.com> References: <20260716061519.765593-1-HimaniRamesh.Barde@windriver.com> MIME-Version: 1.0 X-Proofpoint-GUID: I6psrNGEVPCzQ2AcPnT81hIG2TSOQolV X-Proofpoint-Spam-Info: AW1haW4tMjYwNzIyMDA5OCBTYWx0ZWRfX1NvaPNKbLtU0 eJwxCMl3eplNR3gnJQWxf5MCsURKZvrVtOfUv3XBmoPYMV6ZAVA/lUHz1xWyd2jckyeMGJlUxrM lhKNJ5dqw8znxg2ur3Odfs0X7ReU9vPXMWghs4MQep/xQt6AgbuG X-Proofpoint-ORIG-GUID: I6psrNGEVPCzQ2AcPnT81hIG2TSOQolV X-Authority-Analysis: v=2.4 cv=CfQ4Irrl c=1 sm=1 tr=0 ts=6a6097f0 cx=c_pps a=AbJuCvi4Y3V6hpbCNWx0WA==:117 a=AbJuCvi4Y3V6hpbCNWx0WA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=bi6dqmuHe4P4UrxVR6um:22 a=HK-ge7EqtdluswH-FwHe:22 a=NEAV23lmAAAA:8 a=t7CeM3EgAAAA:8 a=A1W1FX-mHNmlLdSUdnYA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzIyMDA5OCBTYWx0ZWRfXyaf6QNqEfuDm gwjCH6f/7s0iCOKFvjFJH1nGCkb8xtM5ezUIncbcEEZnjBv3cEnCQShtMIaGciI/G8+Bpry38KK UWEXS8JJC/QV/o2kfOL8s7VV8siBz45k6h/324OsjchH4mxOt83bk50QQivPCuYyLfuBWbg8IGm FTzRxfj6XOtiQBR+pe/deRPBgibXI4SqbaNgiER5I443+hjSz0+K/KhO5aKajCMZsOg9lHdGNGf qj3ZqOkQW22s+/A2hqPlhgfyUloib99ch36qPLK5FftYvx0djay6WihAxyYsFJCD9Mr4S0cBmJR hmRk1grrC1jxTo80BNNjATP/2oR7znN5+vyejgGF4ZhZ+nNVddb0ypjPkob1ByCHrPvmNSwgcg6 LWTzu8rcrv3CHTf0CYTsij1lQeuCjSXbGQX/3cwOHaiBkpquGTSaYE8NT1BbuxB0KW0wuOITbQY jcUy1hjPNl1aReN34rw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-22_03,2026-07-21_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 phishscore=0 clxscore=1015 malwarescore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607220098 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 22 Jul 2026 10:36:51 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/241655 When packages are installed outside of Yocto's normal image creation (e.g., using multistrap, debootstrap, or dpkg directly on a host), the postinst script fails to enable systemd services. The issue is that the entire enable logic is gated behind "if type systemctl >/dev/null 2>/dev/null". In cross-install scenarios: - If systemctl is absent on the host: the check fails, script is skipped - If host systemctl is present: it cannot find target unit files Fix this by separating the image-build ($D set) and on-target ($D unset) code paths into distinct branches. The previous code used a single OPTS variable to switch between "--root=$D" (image-build) and "" (on-target) within one unified block. This variable is removed because the two scenarios now have dedicated branches with different logic: - Image-build ($D set): Uses "systemctl --root=$D preset" per service, which reads preset files from the target rootfs and creates symlinks without needing the host systemctl to understand the target's unit files. Falls back to "systemctl --root=$D enable" per service. - On-target ($D unset): Same as before - enable, daemon-reload, preset, restart. No behavioral change for on-target installs. The OPTS variable is no longer needed because each branch now directly uses the appropriate systemctl invocation for its context, making the intent clearer and the image-build path functional. Fixes [YOCTO #14118] Signed-off-by: Himani Ramesh Barde --- meta/classes-recipe/systemd.bbclass | 30 ++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index 26eaaf1..bdbfb7c 100644 --- a/meta/classes-recipe/systemd.bbclass +++ b/meta/classes-recipe/systemd.bbclass @@ -27,24 +27,36 @@ python __anonymous() { } systemd_postinst() { -if type systemctl >/dev/null 2>/dev/null; then - OPTS="" - - if [ -n "$D" ]; then - OPTS="--root=$D" +if [ -n "$D" ]; then + # Image-build/cross-install: apply presets to the target rootfs. + # This handles multistrap, debootstrap, and similar tools that + # install packages outside of Yocto's normal image creation. + if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then + if type systemctl >/dev/null 2>/dev/null; then + for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}; do + systemctl --root=$D preset "$service" 2>/dev/null || \ + systemctl --root=$D enable "$service" 2>/dev/null || true + done + + for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}; do + systemctl --global --root=$D preset "$service" 2>/dev/null || \ + systemctl --global --root=$D enable "$service" 2>/dev/null || true + done + fi fi - +elif type systemctl >/dev/null 2>/dev/null; then + # On-target: running on the actual device if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}; do - systemctl ${OPTS} enable "$service" + systemctl enable "$service" done for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}; do - systemctl --global ${OPTS} enable "$service" + systemctl --global enable "$service" done fi - if [ -z "$D" ] && systemctl >/dev/null 2>/dev/null; then + if systemctl >/dev/null 2>/dev/null; then # Reload only system service manager # --global for daemon-reload is not supported: https://github.com/systemd/systemd/issues/19284 systemctl daemon-reload