]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
systemd.bbclass: Make systemd_postinst run as intended
authorPeter Kjellerstedt <pkj@axis.com>
Mon, 8 Sep 2025 16:05:04 +0000 (18:05 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 11 Sep 2025 09:45:09 +0000 (10:45 +0100)
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 arguments (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>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-recipe/systemd.bbclass

index 0e9f7cfa33776732c7934197d4c8b104338d78cd..4e687135f13317936756189c87832c97b72168da 100644 (file)
@@ -29,7 +29,7 @@ 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
@@ -46,7 +46,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 +66,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)}