Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Peter Kjellerstedt <pkj@axis.com>
To: <openembedded-core@lists.openembedded.org>
Subject: [PATCHv5 2/2] systemd.bbclass: Make systemd_postinst run as intended
Date: Wed, 20 Aug 2025 15:42:02 +0200	[thread overview]
Message-ID: <20250820134202.1412477-2-pkj@axis.com> (raw)
In-Reply-To: <20250820134202.1412477-1-pkj@axis.com>

After the switch from using a systemctl written in Python to using the
official version of systemctl from the systemd project, the
systemd_postinst function has effectively not been executed during the
rootfs creation. The reason is that systemctl provided by
systemctl-native fails if run without argument (as systemd_postinst
does):

  Failed to connect to system scope bus via local transport: Operation
  not permitted (consider using --machine=<user>@.host --user to connect
  to bus of other user)

This is not seen in the logs since stderr is sent to /dev/null, and the
only way to tell that there is a problem is because systemd services
that are expected to be enabled aren't running.

The reason this has gone unnoticed is because systemd_handle_machine_id
in rootfs-postcommands.bbclass will call systemctl preset-all, which in
most cases will create the missing links to enable the systemd services.

This change effectively reverts commit
a52e66762c0c51918b1ba3d4622759637b6e920a (systemd.bbclass: update
command to check systemctl available) and instead only runs systemctl
without arguments (to determine that it can communicate with systemd)
when executed on target.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---

PATCHv2: Add --sysv-install= to $OPTS to instruct systemctl where to
         look for systemd-sysv-install.
PATCHv3: No changes.
PATCHv4: No changes.
PATCHv5: No changes.

 meta/classes-recipe/systemd.bbclass | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
index 12c59647be..0a7de208e8 100644
--- a/meta/classes-recipe/systemd.bbclass
+++ b/meta/classes-recipe/systemd.bbclass
@@ -29,11 +29,16 @@ python __anonymous() {
 }
 
 systemd_postinst() {
-if systemctl >/dev/null 2>/dev/null; then
+if type systemctl >/dev/null 2>/dev/null; then
 	OPTS=""
 
 	if [ -n "$D" ]; then
-		OPTS="--root=$D"
+		# Use ${STAGING_LIBDIR_NATIVE}/systemd rather than
+		# ${STAGING_DIR_NATIVE}${systemd_unitdir} because the latter is
+		# affected by whether the usrmerge distro feature is set _for
+		# target_, and we need to know the path to systemd-sysv-install
+		# where it was installed _for native_.
+		OPTS="--root=$D --sysv-install=${STAGING_LIBDIR_NATIVE}/systemd/systemd-sysv-install"
 	fi
 
 	if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
@@ -46,7 +51,7 @@ if systemctl >/dev/null 2>/dev/null; then
 		done
 	fi
 
-	if [ -z "$D" ]; then
+	if [ -z "$D" ] && 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
@@ -66,8 +71,8 @@ fi
 }
 
 systemd_prerm() {
-if systemctl >/dev/null 2>/dev/null; then
-	if [ -z "$D" ]; then
+if type systemctl >/dev/null 2>/dev/null; then
+	if [ -z "$D" ] && systemctl >/dev/null 2>/dev/null; then
 		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)}


  reply	other threads:[~2025-08-20 13:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20 13:42 [PATCHv5 1/2] systemd-systemctl-native: Install systemd-sysv-install Peter Kjellerstedt
2025-08-20 13:42 ` Peter Kjellerstedt [this message]
2025-08-21  6:38 ` [OE-core] " Mathieu Dubois-Briand
2025-08-21 15:11   ` Peter Kjellerstedt
2025-08-21 19:19     ` Mathieu Dubois-Briand
2025-08-22 18:29       ` Peter Kjellerstedt
2025-08-24  6:37         ` Mathieu Dubois-Briand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250820134202.1412477-2-pkj@axis.com \
    --to=pkj@axis.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox