diff mbox series

[meta-selinux,3/3] selinux-image.bbclass: hold all /.autorelabel handling

Message ID 20260910023825.1829224-3-chenqi_hycx@cetc.com.cn
State New
Headers show
Series [meta-selinux,1/3] selinux-image.bbclass: fix selinux_set_labels | expand

Commit Message

Chen Qi Sept. 10, 2026, 2:38 a.m. UTC
From: Chen Qi <chenqi_hycx@cetc.com.cn>

The /.autorelabel file logically does not belong to any package and
should be something handled in the system level. So we should hold all
/.autorelabel handling logics here. Besides the previous creation on
failure logic, we should also put explicit creation here.

Signed-off-by: Chen Qi <chenqi_hycx@cetc.com.cn>
---
 classes/selinux-image.bbclass | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/classes/selinux-image.bbclass b/classes/selinux-image.bbclass
index 97ff99e..86b3765 100644
--- a/classes/selinux-image.bbclass
+++ b/classes/selinux-image.bbclass
@@ -1,5 +1,8 @@ 
 selinux_set_labels() {
-    if [ -f ${IMAGE_ROOTFS}/${sysconfdir}/selinux/config ]; then
+    if ${@oe.utils.vartrue('FIRST_BOOT_RELABEL', 'true', 'false', d)}; then
+	bbnote "Forcing first boot relabel"
+	echo "# first boot relabelling" > ${IMAGE_ROOTFS}/.autorelabel
+    elif [ -f ${IMAGE_ROOTFS}/${sysconfdir}/selinux/config ]; then
         POL_TYPE=$(sed -n -e "s&^SELINUXTYPE[[:space:]]*=[[:space:]]*\([0-9A-Za-z_]\+\)&\1&p" ${IMAGE_ROOTFS}/${sysconfdir}/selinux/config)
 	bbnote "Running setfiles -m -r ${IMAGE_ROOTFS} ${IMAGE_ROOTFS}/${sysconfdir}/selinux/${POL_TYPE}/contexts/files/file_contexts ${IMAGE_ROOTFS}"
         if ! setfiles -m -r ${IMAGE_ROOTFS} ${IMAGE_ROOTFS}/${sysconfdir}/selinux/${POL_TYPE}/contexts/files/file_contexts ${IMAGE_ROOTFS}
@@ -17,11 +20,10 @@  python selinux_setlabels_handler() {
     if not d or 'selinux' not in d.getVar('DISTRO_FEATURES').split():
         return
 
-    if d.getVar('FIRST_BOOT_RELABEL') == '1':
-        return
-
     d.prependVar('IMAGE_PREPROCESS_COMMAND', ' selinux_set_labels ')
-    d.appendVarFlag('do_image', 'depends', ' policycoreutils-native:do_populate_sysroot')
+
+    if not d.getVar('FIRST_BOOT_RELABEL') == '1':
+        d.appendVarFlag('do_image', 'depends', ' policycoreutils-native:do_populate_sysroot')
 }
 
 addhandler selinux_setlabels_handler