[arch-projects] [initscripts][PATCH] functions: use a pipe for umount_all instead of a PE

Dave Reisner dreisner at archlinux.org
Fri Apr 6 12:28:36 EDT 2012


We don't care about the side effects of the subshell created by the
pipe since everything is localized within this function. Use the more
"canonical" syntax. This should stop the recurring bug reports that we
seem to get from people who think they understand Bash syntax, e.g.

FS#28331
FS#29145
FS#28582
FS#27098

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
This patch sucks to read.

 functions |   41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/functions b/functions
index f59f9dd..d8693e0 100644
--- a/functions
+++ b/functions
@@ -549,32 +549,31 @@ mount_all() {
 umount_all() {
 	# $1: restrict to fstype
 
-	local mounts
+	findmnt -mrunRo TARGET,FSTYPE,OPTIONS / | {
+		while read -r target fstype options; do
+			# match only targetted fstypes
+			if [[ $1 && $1 != "$fstype" ]]; then
+				continue
+			fi
 
-	while read -r target fstype options; do
+			# don't unmount API filesystems
+			if [[ $target = /@(proc|sys|run|dev|dev/pts) ]]; then
+				continue
+			fi
 
-		# match only targetted fstypes
-		if [[ $1 && $1 != "$fstype" ]]; then
-			continue
-		fi
+			# avoid networked devices
+			IFS=, read -ra opts <<< "$options"
+			if in_array _netdev "${opts[@]}"; then
+				continue
+			fi
 
-		# don't unmount API filesystems
-		if [[ $target = /@(proc|sys|run|dev|dev/pts) ]]; then
-			continue
-		fi
+			mounts=("$target" "${mounts[@]}")
+		done
 
-		# avoid networked devices
-		IFS=, read -ra opts <<< "$options"
-		if in_array _netdev "${opts[@]}"; then
-			continue
+		if (( ${#mounts[*]} )); then
+			umount -r "${mounts[@]}"
 		fi
-
-		mounts=("$target" "${mounts[@]}")
-	done < <(findmnt -mrunRo TARGET,FSTYPE,OPTIONS /)
-
-	if (( ${#mounts[*]} )); then
-		umount -r "${mounts[@]}"
-	fi
+	}
 
 }
 
-- 
1.7.9.6



More information about the arch-projects mailing list