diff mbox series

systemd-compat-units: generate masks at build time

Message ID 20260113184632.3953060-1-ross.burton@arm.com
State New
Headers show
Series systemd-compat-units: generate masks at build time | expand

Commit Message

Ross Burton Jan. 13, 2026, 6:46 p.m. UTC
Originally, this recipe masked the units at rootfs-time by looking to see
if the init script to be masked existed, and masking it if so.

That however suffers from a race condition where the postinst script may
be executed before the package that provides a script has been installed
so this was changed to be an on-target postinst[1], so we know that all
of the packages have been installed.

However, this now means that you can't have an image that install this
package _and_ is read-only, because we have an on-target postinst to
execute.

There's also another problem that with on-target package management, it
would be possible to install a package that should be masked after the
postinst has been executed, so the mask won't exist.

Taking a step back, a systemd unit mask is just a symlink to /dev/null
with the right name in the right path.  So instead of masking in a post-
install script, we can generate all the masks at build-time.

This change reduces this package to just a number of symlinks, with no
post-install scripts.

[ YOCTO #16109 ]
[1] oe-core e88f22da19 ("systemd-compat-units: execute postinst on target")

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 .../systemd/systemd-compat-units.bb           | 34 ++++---------------
 1 file changed, 6 insertions(+), 28 deletions(-)
diff mbox series

Patch

diff --git a/meta/recipes-core/systemd/systemd-compat-units.bb b/meta/recipes-core/systemd/systemd-compat-units.bb
index d6da34e9b8..6839101037 100644
--- a/meta/recipes-core/systemd/systemd-compat-units.bb
+++ b/meta/recipes-core/systemd/systemd-compat-units.bb
@@ -2,18 +2,14 @@  SUMMARY = "Enhances systemd compatilibity with existing SysVinit scripts"
 HOMEPAGE = "http://www.freedesktop.org/wiki/Software/systemd"
 LICENSE = "MIT"
 
-PACKAGE_WRITE_DEPS += "systemd-systemctl-native"
+DEPENDS = "systemd-systemctl-native"
+INHIBIT_DEFAULT_DEPS = "1"
 
 S = "${UNPACKDIR}"
 
 inherit features_check
 
-INHIBIT_DEFAULT_DEPS = "1"
-
-ALLOW_EMPTY:${PN} = "1"
-
-REQUIRED_DISTRO_FEATURES += "systemd"
-REQUIRED_DISTRO_FEATURES += "usrmerge"
+REQUIRED_DISTRO_FEATURES = "systemd"
 
 SYSTEMD_DISABLED_SYSV_SERVICES = " \
   busybox-udhcpc \
@@ -24,26 +20,8 @@  SYSTEMD_DISABLED_SYSV_SERVICES = " \
   syslog.busybox \
 "
 
-pkg_postinst_ontarget:${PN} () {
-
-	test -d $D${sysconfdir}/init.d  ||  exit 0
-	cd $D${sysconfdir}/init.d
-
-	echo "Disabling the following sysv scripts: "
-
-	if [ -n "$D" ]; then
-		OPTS="--root=$D"
-	else
-		OPTS=""
-	fi
-
-	for i in ${SYSTEMD_DISABLED_SYSV_SERVICES} ; do
-		if [ -e $i -o -e $i.sh ]  &&   ! [ -e $D${sysconfdir}/systemd/system/$i.service -o -e $D${systemd_system_unitdir}/$i.service ] ; then
-			echo -n "$i: "
-			systemctl $OPTS mask $i.service
-		fi
+do_install() {
+	for unit in ${SYSTEMD_DISABLED_SYSV_SERVICES} ; do
+		systemctl --root ${D} mask $unit
 	done
-	echo
 }
-
-RDEPENDS:${PN} = "systemd"