ports/76915: [patch] Handle port deinstall scripts when /var is mounted noexec

Michel Lavondes fox at vader.aacc.cc.md.us
Mon Jan 31 19:00:37 UTC 2005


>Number:         76915
>Category:       ports
>Synopsis:       [patch] Handle port deinstall scripts when /var is mounted noexec
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 31 19:00:36 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Michel Lavondes
>Release:        4.8-Release-p27
>Organization:
Ecdysiasts United for Overdressing
>Environment:
>Description:
When /var (or whichever filesystem holds PKG_DBDIR) is mounted noexec, attempts to deinstall ports will fail and leave a mess behind if the port has a require or deinstall script. This patch checks for that and skips deinstalling if that is the case.
>How-To-Repeat:
mount -u -o noexec /var
cd /usr/ports/www/firefox
make deinstall

or:

mount -u -o noexec /var
cd /usr/ports/www/firefox
make deinstall-all
>Fix:
Apply the following patch (also available from http://www.livejournal.com/users/pauamma/13489.html) to ports/Mk/bsd.ports.mk (warning: tested under FreeBSD 4.8 only)

--- ports/Mk/bsd.port.mk.orig	Sat Jan 29 02:11:04 2005
+++ ports/Mk/bsd.port.mk	Sat Jan 29 00:04:45 2005
@@ -919,6 +919,7 @@
 FILE?=		/usr/bin/file
 FIND?=		/usr/bin/find
 FMT?=		/usr/bin/fmt
+FSTAT?=		/usr/bin/fstat
 GREP?=		/usr/bin/grep
 GUNZIP_CMD?=	/usr/bin/gunzip -f
 GZCAT?=		/usr/bin/gzcat
@@ -3818,19 +3819,32 @@
 	@${ECHO_MSG} "===>  Deinstalling for ${PKGORIGIN}"
 	@found_names=`${PKG_INFO} -q -O ${PKGORIGIN}`; \
 	for p in $${found_names}; do \
-			check_name=`${ECHO_CMD} $${p} | ${SED} -e 's/-[^-]*$$//'`; \
-			if [ "$${check_name}" = "${PKGBASE}" ]; then \
-					prfx=`${PKG_INFO} -q -p $${p} 2> /dev/null | ${SED} -ne '1s|^@cwd ||p'`; \
-					if [ "x${PREFIX}" = "x$${prfx}" ]; then \
-							${ECHO_MSG} "===>   Deinstalling $${p}"; \
-							${PKG_DELETE} -f $${p}; \
-					else \
-							${ECHO_MSG} "===>   $${p} has a different PREFIX: $${prfx}, skipping"; \
+		check_name=`${ECHO_CMD} $${p} | ${SED} -e 's/-[^-]*$$//'`; \
+		if [ "$${check_name}" = "${PKGBASE}" ]; then \
+			cannot_exec=""; \
+			for f in +REQUIRE +DEINSTALL +POST-DEINSTALL; do \
+				if [ -e ${PKG_DBDIR}/$${p}/$${f} ]; then \
+					: 'Is the filesystem f is on mounted noexec?'; \
+					if /sbin/mount -p | ${AWK} '{ print $$2, $$4 }' | ${GREP} "^`${FSTAT} ${PKG_DBDIR}/$${p}/$${f} < ${PKG_DBDIR}/$${p}/$${f} | ${GREP} ${PKG_DBDIR}/$${p}/$${f} | ${AWK} '{ print $$5 }'` " | ${GREP} -q noexec; then \
+						cannot_exec=${PKG_DBDIR}/$${p}/$${f}; \
 					fi; \
+				fi; \
+			done; \
+			if [ -z "$${cannot_exec}" ]; then \
+				prfx=`${PKG_INFO} -q -p $${p} 2> /dev/null | ${SED} -ne '1s|^@cwd ||p'`; \
+				if [ "x${PREFIX}" = "x$${prfx}" ]; then \
+					${ECHO_MSG} "===>   Deinstalling $${p}"; \
+					${PKG_DELETE} -f $${p}; \
+				else \
+					${ECHO_MSG} "===>   $${p} has a different PREFIX: $${prfx}, skipping"; \
+				fi; \
+			else \
+				${ECHO_MSG} "===>   $${p} has deinstall script $${cannot_exec} on a filesystem mounted noexec, skipping"; \
 			fi; \
+		fi; \
 	done; \
 	if [ -z "$${found_names}" ]; then \
-			${ECHO_MSG} "===>   ${PKGBASE} not installed, skipping"; \
+		${ECHO_MSG} "===>   ${PKGBASE} not installed, skipping"; \
 	fi
 	@${RM} -f ${INSTALL_COOKIE} ${PACKAGE_COOKIE}
 .endif
@@ -3852,8 +3866,21 @@
 	@deinstall_names=`${PKG_INFO} -q -O ${PKGORIGIN}`; \
 	if [ -n "$${deinstall_names}" ]; then \
 		for d in $${deinstall_names}; do \
-			${ECHO_MSG} "===>   Deinstalling $${d}"; \
-			${PKG_DELETE} -f $${d}; \
+			cannot_exec=""; \
+			for f in +REQUIRE +DEINSTALL +POST-DEINSTALL; do \
+				if [ -e ${PKG_DBDIR}/$${d}/$${f} ]; then \
+					: 'Is the filesystem f is on mounted noexec?'; \
+					if /sbin/mount -p | ${AWK} '{ print $$2, $$4 }' | ${GREP} "^`${FSTAT} ${PKG_DBDIR}/$${d}/$${f} < ${PKG_DBDIR}/$${d}/$${f} | ${GREP} ${PKG_DBDIR}/$${d}/$${f} | ${AWK} '{ print $$5 }'` " | ${GREP} -q noexec; then \
+						cannot_exec=${PKG_DBDIR}/$${d}/$${f}; \
+					fi; \
+				fi; \
+			done; \
+			if [ -z "$${cannot_exec}" ]; then \
+				${ECHO_MSG} "===>   Deinstalling $${d}"; \
+				${PKG_DELETE} -f $${d}; \
+			else \
+				${ECHO_MSG} "===>   $${d} has deinstall script $${cannot_exec} on a filesystem mounted noexec, skipping"; \
+			fi; \
 		done; \
 	else \
 		${ECHO_MSG} "===>   ${PKGORIGIN} not installed, skipping"; \

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list