| Message ID | 20250812211424.76559-1-pkj@axis.com |
|---|---|
| State | New |
| Headers | show |
| Series | systemd.bbclass: Make systemd_postinst run as intended | expand |
On Tue, 12 Aug 2025 at 23:14, Peter Kjellerstedt via lists.openembedded.org <peter.kjellerstedt=axis.com@lists.openembedded.org> wrote: > - if [ -z "$D" ]; then > + if [ -z "$D" ] && systemctl >/dev/null 2>/dev/null; then etc. Ugh. Is it possible to *not* do this >dev/null 2>dev/null thing? Discarding output, and especially discarding stderr has been shown time and again to cause headaches when things go wrong (and they do). Alex
On Tue Aug 12, 2025 at 11:14 PM CEST, Peter Kjellerstedt via lists.openembedded.org wrote: > 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> > --- Hi Peter, It looks like this is breaking the build in some configurations: ERROR: core-image-sato-1.0-r0 do_rootfs: Postinstall scriptlets of ['bluez5', 'ofono', 'connman', 'xserver-nodm-init', 'avahi-daemon', 'rpcbind', 'run-postinsts'] 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. https://autobuilder.yoctoproject.org/valkyrie/#/builders/26/builds/2193 Can you have a look at these errors please? Best regards, Mathieu
On Wed Aug 13, 2025 at 12:10 PM CEST, Mathieu Dubois-Briand wrote: > On Tue Aug 12, 2025 at 11:14 PM CEST, Peter Kjellerstedt via lists.openembedded.org wrote: >> 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> >> --- > > Hi Peter, > > It looks like this is breaking the build in some configurations: > > ERROR: core-image-sato-1.0-r0 do_rootfs: Postinstall scriptlets of ['bluez5', 'ofono', 'connman', 'xserver-nodm-init', 'avahi-daemon', 'rpcbind', 'run-postinsts'] 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. > > https://autobuilder.yoctoproject.org/valkyrie/#/builders/26/builds/2193 > > Can you have a look at these errors please? > > Best regards, > Mathieu I just saw selftests are also failing for the same reason: 2025-08-13 08:15:22,377 - oe-selftest - INFO - overlayfs.OverlayFSTests.test_not_all_units_installed (subunit.RemotedTestCase) 2025-08-13 08:15:22,388 - oe-selftest - INFO - ... FAIL ... ERROR: core-image-minimal-1.0-r0 do_rootfs: Postinstall scriptlets of ['run-postinsts'] have failed. If the intention is to defer them to first boot, https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2141 https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/2069
> -----Original Message----- > From: Alexander Kanavin <alex.kanavin@gmail.com> > Sent: den 13 augusti 2025 10:57 > To: Peter Kjellerstedt <peter.kjellerstedt@axis.com> > Cc: openembedded-core@lists.openembedded.org > Subject: Re: [OE-core] [PATCH] systemd.bbclass: Make systemd_postinst run > as intended > > On Tue, 12 Aug 2025 at 23:14, Peter Kjellerstedt via > lists.openembedded.org > <peter.kjellerstedt=axis.com@lists.openembedded.org> wrote: > > - if [ -z "$D" ]; then > > + if [ -z "$D" ] && systemctl >/dev/null 2>/dev/null; then > > etc. > > Ugh. Is it possible to *not* do this >dev/null 2>dev/null thing? > Discarding output, and especially discarding stderr has been shown > time and again to cause headaches when things go wrong (and they do). > > Alex While I understand your concern, the above change just copied the original code. Since this is part of an if-statement, where it is expected that the systemctl command will fail under some conditions, allowing stderr to be output to the logs would probably be confusing. //Peter
> -----Original Message----- > From: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> > Sent: den 13 augusti 2025 12:15 > To: Peter Kjellerstedt <peter.kjellerstedt@axis.com>; openembedded- > core@lists.openembedded.org > Subject: Re: [OE-core] [PATCH] systemd.bbclass: Make systemd_postinst run > as intended > > On Wed Aug 13, 2025 at 12:10 PM CEST, Mathieu Dubois-Briand wrote: > > On Tue Aug 12, 2025 at 11:14 PM CEST, Peter Kjellerstedt via lists.openembedded.org wrote: > >> 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> > >> --- > > > > Hi Peter, > > > > It looks like this is breaking the build in some configurations: > > > > ERROR: core-image-sato-1.0-r0 do_rootfs: Postinstall scriptlets of ['bluez5', 'ofono', 'connman', 'xserver-nodm-init', 'avahi-daemon', 'rpcbind', 'run-postinsts'] 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. > > > > https://autobuilder.yoctoproject.org/valkyrie/#/builders/26/builds/2193 > > > > Can you have a look at these errors please? > > > > Best regards, > > Mathieu > > I just saw selftests are also failing for the same reason: > > 2025-08-13 08:15:22,377 - oe-selftest - INFO - overlayfs.OverlayFSTests.test_not_all_units_installed (subunit.RemotedTestCase) > 2025-08-13 08:15:22,388 - oe-selftest - INFO - ... FAIL > ... > ERROR: core-image-minimal-1.0-r0 do_rootfs: Postinstall scriptlets of ['run-postinsts'] have failed. If the intention is to defer them to first boot, > > https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2141 > https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/2069 > > -- > Mathieu Dubois-Briand, Bootlin > Embedded Linux and Kernel engineering > https://bootlin.com All of these failures were due to `systemctl enable` now actually being executed during the build, and when both support for systemd and sysvinit are enabled in DISTRO_FEATURES, then systemctl expects a systemd-sysv-install helper to be available, which it wasn't. Adding it was simple enough, as it was installed by the systemd recipe, although it needed a slight modification to support the --root option. However, the real problem was that the path to systemd-sysv-install is hardcoded into systemctl, and of course it does not work when being run from a sysroot, where the path does not match what was used when it was built. I had to add a patch for systemctl to allow the path to be provided in runtime. I have sent the patch upstream, but it has already been rejected with the motivation that support for sysv-install will be removed in the near future (which means I will have to send a v3 of my patches to correct the Upstream-Status)... //Peter
diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index 12c59647be..3d8ca24a68 100644 --- a/meta/classes-recipe/systemd.bbclass +++ b/meta/classes-recipe/systemd.bbclass @@ -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)}
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> --- meta/classes-recipe/systemd.bbclass | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)