systemd-systemctl-native: Use += instead of :append
PATCH 1/3 systemd-systemctl-native: Use += instead of :append
From: Peter Kjellerstedt <[email protected]>
There is no reason to use EXTRA_OEMESON:append when += will do.
--- meta/recipes-core/systemd/systemd-systemctl-native_257.6.bb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
meta/recipes-core/systemd/systemd-systemctl-native_257.6.bb +2 -2
@@ -8,9 +8,9 @@ inherit pkgconfig meson native MESON_TARGET = "systemctl:executable" MESON_INSTALL_TAGS = "systemctl" -EXTRA_OEMESON:append = " -Dlink-systemctl-shared=false" +EXTRA_OEMESON += "-Dlink-systemctl-shared=false" # Systemctl is supposed to operate on target, but the target sysroot is not # determined at run-time, but rather set during configure # More details are here https://github.com/systemd/systemd/issues/35897#issuecomment-2665405887 -EXTRA_OEMESON:append = " --sysconfdir ${sysconfdir_native}" +EXTRA_OEMESON += "--sysconfdir ${sysconfdir_native}"
PATCH 2/3 systemd-systemctl-native: Install systemd-sysv-install
It is needed when support for both systemd and sysvinit are enabled.
This also adds a patch for systemctl to call systemd-sysv-install without a hardcoded path and instead relies on finding it in $PATH. This is needed when calling systemctl from a recipe sysroot.
---
Compared to the corresponding change integrated to master, I have removed the comment about upgrading to systemd 259 as that will never happen for Walnascar.
.../systemd/systemd-systemctl-native_257.6.bb | 11 ++++++ ...ll-systemd-sysv-install-without-path.patch | 37 +++++++++++++++++++ ...implment-systemd-sysv-install-for-OE.patch | 13 +++---- 3 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 meta/recipes-core/systemd/systemd/0001-systemctl-Call-systemd-sysv-install-without-path.patch
meta/recipes-core/systemd/systemd-systemctl-native_257.6.bb +11 -0
@@ -1,9 +1,14 @@ +FILESEXTRAPATHS:prepend := "${THISDIR}/systemd:" + SUMMARY = "Systemctl executable from systemd" require systemd.inc DEPENDS = "gperf-native libcap-native util-linux-native python3-jinja2-native" +SRC_URI += "file://0001-systemctl-Call-systemd-sysv-install-without-path.patch" +SRC_URI += "file://0002-implment-systemd-sysv-install-for-OE.patch" + inherit pkgconfig meson native MESON_TARGET = "systemctl:executable"
@@ -14,3 +19,9 @@ EXTRA_OEMESON += "-Dlink-systemctl-shared=false" # determined at run-time, but rather set during configure # More details are here https://github.com/systemd/systemd/issues/35897#issuecomment-2665405887 EXTRA_OEMESON += "--sysconfdir ${sysconfdir_native}" + +do_install:append() { + # Install systemd-sysv-install in /usr/bin rather than /usr/lib/systemd + # (where it is normally installed) so systemctl can find it in $PATH. + install -Dm 0755 ${S}/src/systemctl/systemd-sysv-install.SKELETON ${D}${bindir}/systemd-sysv-install +}
meta/recipes-core/systemd/systemd/0001-systemctl-Call-systemd-sysv-install-without-path.patch new file +37 -0
@@ -0,0 +1,37 @@ +From 34c8551a8b16bf235a1ebe8d9cb1a3474a7c975e Mon Sep 17 00:00:00 2001 +From: Peter Kjellerstedt <[email protected]> +Date: Fri, 22 Aug 2025 18:07:28 +0200 +Subject: [PATCH] systemctl: Call systemd-sysv-install without path + +Expect to find systemd-sysv-install in $PATH instead of hardcoding the +path to it, as the latter does not work when running systemctl from a +recipe sysroot. + +Signed-off-by: Peter Kjellerstedt <[email protected]> +Upstream-Status: Inappropriate [OE specific] +--- + src/systemctl/systemctl-sysv-compat.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/systemctl/systemctl-sysv-compat.c b/src/systemctl/systemctl-sysv-compat.c +index cb9c43e3dc..e44ef9f64e 100644 +--- a/src/systemctl/systemctl-sysv-compat.c ++++ b/src/systemctl/systemctl-sysv-compat.c +@@ -140,7 +140,7 @@ int enable_sysv_units(const char *verb, char **args) { + while (args[f]) { + + const char *argv[] = { +- LIBEXECDIR "/systemd-sysv-install", ++ "systemd-sysv-install", + NULL, /* --root= */ + NULL, /* verb */ + NULL, /* service */ +@@ -218,7 +218,7 @@ int enable_sysv_units(const char *verb, char **args) { + return j; + if (j == 0) { + /* Child */ +- execv(argv[0], (char**) argv); ++ execvp(argv[0], (char**) argv); + log_error_errno(errno, "Failed to execute %s: %m", argv[0]); + _exit(EXIT_FAILURE); + }
meta/recipes-core/systemd/systemd/0002-implment-systemd-sysv-install-for-OE.patch +5 -8
@@ -1,7 +1,7 @@ -From fab8c573d06340868f070446118673b1c23584c5 Mon Sep 17 00:00:00 2001 +From 4a5602ede9881fd8e578a3c8bc40dd5df7c4d802 Mon Sep 17 00:00:00 2001 From: Khem Raj <[email protected]> Date: Sat, 5 Sep 2015 06:31:47 +0000 -Subject: [PATCH 02/26] implment systemd-sysv-install for OE +Subject: [PATCH] implement systemd-sysv-install for OE Use update-rc.d for enabling/disabling and status command to check the status of the sysv service
@@ -14,7 +14,7 @@ Signed-off-by: Khem Raj <[email protected]> 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/systemctl/systemd-sysv-install.SKELETON b/src/systemctl/systemd-sysv-install.SKELETON -index cb58d8243b..000bdf6165 100755 +index cb58d8243b..eff3f5f579 100755 --- a/src/systemctl/systemd-sysv-install.SKELETON +++ b/src/systemctl/systemd-sysv-install.SKELETON @@ -34,17 +34,17 @@ case "$1" in
@@ -22,13 +22,13 @@ index cb58d8243b..000bdf6165 100755 # call the command to enable SysV init script $NAME here # (consider optional $ROOT) - echo "IMPLEMENT ME: enabling SysV init.d script $NAME" -+ update-rc.d -f $NAME defaults ++ update-rc.d ${ROOT:+-r $ROOT} -f $NAME defaults ;; disable) # call the command to disable SysV init script $NAME here # (consider optional $ROOT) - echo "IMPLEMENT ME: disabling SysV init.d script $NAME" -+ update-rc.d -f $NAME remove ++ update-rc.d ${ROOT:+-r $ROOT} -f $NAME remove ;; is-enabled) # exit with 0 if $NAME is enabled, non-zero if it is disabled
@@ -38,6 +38,3 @@ index cb58d8243b..000bdf6165 100755 ;; *) usage ;; --- -2.34.1 -
PATCH 3/3 systemd.bbclass: Make systemd_postinst run as intended
In reply to Peter KjellerstedtAfter 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.
--- meta/classes-recipe/systemd.bbclass | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
meta/classes-recipe/systemd.bbclass +4 -4
@@ -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)}
Re: [walnascar][PATCH 3/3] systemd.bbclass: Make systemd_postinst run as intended
Hi Peter,
After pulling poky [walnascar] today, our image build broke with the below:
WARNING: nanomind-dev-image-1.0-r0 do_rootfs: nanomind-gpio-ctrl.postinst returned 1, marking as unpacked only, configuration required on target.
WARNING: nanomind-dev-image-1.0-r0 do_rootfs: nanomind-bank-ctrl.postinst returned 1, marking as unpacked only, configuration required on target.
ERROR: nanomind-dev-image-1.0-r0 do_rootfs: Postinstall scriptlets of ['nanomind-gpio-ctrl', 'nanomind-bank-ctrl'] have failed. If the intention is to defer them to first boot, then please place them into pkg_postinst_ontarget:${PN} ().
Deferring to first boot via 'exit 1' is no longer supported.
I noticed this particular commit, and reverting it resolves the breakage. The recipe is quite trivial IMO:
inherit systemd
RDEPENDS:${PN} = "libgpiod-tools"
SYSTEMD_SERVICE:${BPN} = "${BPN}@.service"SRC_URI = "file://${SYSTEMD_SERVICE:${BPN}}"
S = "${WORKDIR}/sources"
UNPACKDIR = "${S}"do_install () {
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${UNPACKDIR}/${SYSTEMD_SERVICE:${BPN}} ${D}${systemd_system_unitdir} }
We are building a readonly rootfs, could this be an issue combined with your patch?
Thanks,
Martin
RE: [OE-core] [walnascar][PATCH 3/3] systemd.bbclass: Make systemd_postinst run as intended
You will have to look into the log.do_rootfs file to figure out why the postinst functions are failing. Before my patch, the postinst functions from systemd were not running so any existing problems would have gone unnoticed.
//Peter
From: [email protected] <[email protected]> On Behalf Of Martin Siegumfeldt via lists.openembedded.org
Sent: den 24 september 2025 20:03
To: [email protected]
Subject: Re: [OE-core] [walnascar][PATCH 3/3] systemd.bbclass: Make systemd_postinst run as intended
Hi Peter,
After pulling poky [walnascar] today, our image build broke with the below:
WARNING: nanomind-dev-image-1.0-r0 do_rootfs: nanomind-gpio-ctrl.postinst returned 1, marking as unpacked only, configuration required on target.
WARNING: nanomind-dev-image-1.0-r0 do_rootfs: nanomind-bank-ctrl.postinst returned 1, marking as unpacked only, configuration required on target.
ERROR: nanomind-dev-image-1.0-r0 do_rootfs: Postinstall scriptlets of ['nanomind-gpio-ctrl', 'nanomind-bank-ctrl'] have failed. If the intention is to defer them to first boot, then please place them into pkg_postinst_ontarget:${PN} ().
Deferring to first boot via 'exit 1' is no longer supported.
I noticed this particular commit, and reverting it resolves the breakage. The recipe is quite trivial IMO:
inherit systemd
RDEPENDS:${PN} = "libgpiod-tools"
SYSTEMD_SERVICE:${BPN} = "${BPN}@.service<mailto:$%7bBPN%[email protected]>"SRC_URI = "file://${SYSTEMD_SERVICE:${BPN}}"
S = "${WORKDIR}/sources"
UNPACKDIR = "${S}"
do_install () {
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${UNPACKDIR}/${SYSTEMD_SERVICE:${BPN}} ${D}${systemd_system_unitdir}
}We are building a readonly rootfs, could this be an issue combined with your patch?
Thanks,
Martin
Re: [walnascar][PATCH 3/3] systemd.bbclass: Make systemd_postinst run as intended
Thanks Peter,
Below is what I expect to be the relevant part of the log file:
Created symlink '/home/martin/work/distro-gomspace_tmp/build/tmp/work/nanomind_z7020_zed-gomspace-linux-gnueabi/nanomind-dev-image/1.0/rootfs/etc/systemd/system/multi-user.target.wants/busybox-klogd.service' → '/usr/lib/systemd/system/busybox-klogd.service'. Created symlink '/home/martin/work/distro-gomspace_tmp/build/tmp/work/nanomind_z7020_zed-gomspace-linux-gnueabi/nanomind-dev-image/1.0/rootfs/etc/systemd/system/multi-user.target.wants/sysstat.service' → '/usr/lib/systemd/system/sysstat.service'. Failed to enable unit: Refusing to operate on template unit [email protected] when destination unit multi-user.target is a non-template unit
Failed to enable unit: Refusing to operate on template unit [email protected] when destination unit multi-user.target is a non-template unit
Created symlink '/home/martin/work/distro-gomspace_tmp/build/tmp/work/nanomind_z7020_zed-gomspace-linux-gnueabi/nanomind-dev-image/1.0/rootfs/etc/systemd/system/multi-user.target.wants/redis.service' → '/usr/lib/systemd/system/redis.service'. .
.
.
Configuring sysstat.
Configuring nanomind-gpio-ctrl.
nanomind-gpio-ctrl.postinst returned 1, marking as unpacked only, configuration required on target.
Configuring nanomind-bank-ctrl.
nanomind-bank-ctrl.postinst returned 1, marking as unpacked only, configuration required on target.
Configuring bash-completion.
Configuring libiio-bash-completion.
The particular service file is described as:
[Unit]
Description=GPIO Control Service (%i)
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/gpioset --daemonize --chip gpiochip0 %i=1 ExecStartPost=/bin/sleep .3 ExecStopPost=/usr/bin/gpioset --toggle 0 --chip gpiochip0 %i=0 ExecStopPost=/bin/sleep .3
[Install]
WantedBy=multi-user.target
AFAICT, the issue only applies for template units - other seem to install/configure fine.
What puzzles me is why I am seemingly the only one running into this - I consider both the recipe and service file to be quite standard...
Re: [walnascar][PATCH 3/3] systemd.bbclass: Make systemd_postinst run as intended
Just fyi, issue appears related to non-instantiated template services - i.e. the below contruct:
SYSTEMD_SERVICE:${BPN} = "${BPN}@.service"
which in the past was not an issue for the rootfs creation.
It may have been an "undocumented feature" so far, and I guess such services in fact should be disabled (SYSTEMD_AUTO_ENABLE = "disable"). At least, doing so enables the rootfs to succeed.
Thanks