[PATCH 2/6] selinux-policy-2.eclass: selinux-policy-2_pkg_postinst: invert check

Rahul Sandhu <[email protected]> Sat, 20 Jun 2026 07:21:29 +0000
Newsgroups gmane.linux.gentoo.devel
Message-ID <[email protected]>
Remove a level of nesting by early returning if we're upgrading modules
instead of removing them altogether.

Signed-off-by: Rahul Sandhu <[email protected]>
---
 eclass/selinux-policy-2.eclass | 48 ++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/eclass/selinux-policy-2.eclass b/eclass/selinux-policy-2.eclass
index 0ccd3706db80..dcf0b3ccce83 100644
--- a/eclass/selinux-policy-2.eclass
+++ b/eclass/selinux-policy-2.eclass
@@ -380,33 +380,35 @@ selinux-policy-2_pkg_postinst() {
 # Uninstall the module(s) from the SELinux policy stores, effectively
 # deactivating the policy on the system.
 selinux-policy-2_pkg_postrm() {
-	# Only if we are not upgrading
-	if [[ -z "${REPLACED_BY_VERSION}" ]]; then
-		# Set root path and don't load policy into the kernel when cross compiling
-		local root_opts=""
-		if [[ -n ${ROOT} ]]; then
-			root_opts="-p ${ROOT} -n"
-		fi
+	if [[ -n "${REPLACED_BY_VERSION}" ]]; then
+		# Don't remove modules if we're upgrading
+		return
+	fi
 
-		# build up the command in the case of multiple modules
-		local COMMAND
-		for i in ${MODS}; do
-			COMMAND="-r ${i} ${COMMAND}"
-		done
+	# Set root path and don't load policy into the kernel when cross compiling
+	local root_opts=""
+	if [[ -n ${ROOT} ]]; then
+		root_opts="-p ${ROOT} -n"
+	fi
+
+	# build up the command in the case of multiple modules
+	local COMMAND
+	for i in ${MODS}; do
+		COMMAND="-r ${i} ${COMMAND}"
+	done
 
-		for type in targeted strict mcs mls; do
-			if use "selinux_policy_types_${type}"; then
-				einfo "Removing the following modules from the ${type} module store: ${MODS}"
+	for type in targeted strict mcs mls; do
+		if use "selinux_policy_types_${type}"; then
+			einfo "Removing the following modules from the ${type} module store: ${MODS}"
 
-				semodule ${root_opts} -s ${type} ${COMMAND}
-				if [[ $? -ne 0 ]]; then
-					ewarn "SELinux module unload failed."
-				else
-					einfo "SELinux modules unloaded successfully."
-				fi
+			semodule ${root_opts} -s ${type} ${COMMAND}
+			if [[ $? -ne 0 ]]; then
+				ewarn "SELinux module unload failed."
+			else
+				einfo "SELinux modules unloaded successfully."
 			fi
-		done
-	fi
+		fi
+	done
 }
 
 fi
-- 
2.54.0