From 3bd074fd404b4863d811d0a50e9ef484523c6b57 Mon Sep 17 00:00:00 2001 From: Miloslav Trmac Date: Mon, 8 May 2006 23:54:06 +0000 Subject: Fix handling of mount points with white space (#186713): - src/fstab-decode.c, src/fstab-decode.8: New files. - src/Makefile: Build and install fstab-decode. - initscripts.spec: Add fstab-decode to %files - rc.d/init.d/functions (fstab_decode_str): New function. (__umount_loop, __umount_loopback_loop): Factor out from copy&pasted copies. (action): Fix command quoting. - rc.d/rc.sysinit: Correctly quote and decode mount points. - rc.d/init.d/halt: Use __umount_* and fstab-decode. (action): Rename from runcmd. Fix command quoting. - rc.d/init.d/netfs: Use __umount_*. --- rc.d/init.d/functions | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'rc.d/init.d/functions') diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index 74fd3d05..f1844d54 100755 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -68,6 +68,11 @@ else INITLOG_ARGS= fi +# Interpret escape sequences in an fstab entry +fstab_decode_str() { + fstab-decode echo "$1" +} + # Check if $pid (could be plural) are running checkpid() { local i @@ -78,6 +83,60 @@ checkpid() { return 1 } +# __umount_loop awk_program fstab_file first_msg retry_msg umount_args +# awk_program should process fstab_file and return a list of fstab-encoded +# paths; it doesn't have to handle comments in fstab_file. +__umount_loop() { + local remaining sig= + local retry=3 + + remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r) + while [ -n "$remaining" -a "$retry" -gt 0 ]; do + if [ "$retry" -eq 3 ]; then + action "$3" fstab-decode umount $5 $remaining + else + action "$4" fstab-decode umount $5 $remaining + fi + sleep 2 + remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r) + [ -z "$remaining" ] && break + fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null + sleep 5 + retry=$(($retry -1)) + sig=-9 + done +} + +# Similar to __umount loop above, specialized for loopback devices +__umount_loopback_loop() { + local remaining devremaining sig= + local retry=3 + + remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts) + devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts) + while [ -n "$remaining" -a "$retry" -gt 0 ]; do + if [ "$retry" -eq 3 ]; then + action $"Unmounting loopback filesystems: " \ + fstab-decode umount $remaining + else + action $"Unmounting loopback filesystems (retry):" \ + fstab-decode umount $remaining + fi + for dev in $devremaining ; do + losetup $dev > /dev/null 2>&1 && \ + action $"Detaching loopback device $dev: " \ + losetup -d $dev + done + remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts) + devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts) + [ -z "$remaining" ] && break + fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null + sleep 5 + retry=$(($retry -1)) + sig=-9 + done +} + # __proc_pids {program} [pidfile] # Set $pid to pids from /var/run* for {program}. $pid should be declared # local in the caller. @@ -442,7 +501,7 @@ action() { echo -n "$STRING " > /etc/rhgb/temp/rhgb-console fi shift - $* && success $"$STRING" || failure $"$STRING" + "$@" && success $"$STRING" || failure $"$STRING" rc=$? echo if [ "${RHGB_STARTED:-}" != "" -a -w /etc/rhgb/temp/rhgb-console ]; then -- cgit v1.2.1