aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d/init.d/halt
diff options
context:
space:
mode:
authorMiloslav Trmac <mitr@volny.cz>2006-05-08 23:54:06 +0000
committerMiloslav Trmac <mitr@volny.cz>2006-05-08 23:54:06 +0000
commit3bd074fd404b4863d811d0a50e9ef484523c6b57 (patch)
tree9c4ca48303377ab77a8a00d10561ba1e8afbab28 /rc.d/init.d/halt
parent0414be84b33e98510feb1d0e281b089ba16b349d (diff)
downloadinitscripts-3bd074fd404b4863d811d0a50e9ef484523c6b57.tar
initscripts-3bd074fd404b4863d811d0a50e9ef484523c6b57.tar.gz
initscripts-3bd074fd404b4863d811d0a50e9ef484523c6b57.tar.bz2
initscripts-3bd074fd404b4863d811d0a50e9ef484523c6b57.tar.xz
initscripts-3bd074fd404b4863d811d0a50e9ef484523c6b57.zip
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_*.
Diffstat (limited to 'rc.d/init.d/halt')
-rwxr-xr-xrc.d/init.d/halt110
1 files changed, 27 insertions, 83 deletions
diff --git a/rc.d/init.d/halt b/rc.d/init.d/halt
index 25fba6f7..d1ff19bf 100755
--- a/rc.d/init.d/halt
+++ b/rc.d/init.d/halt
@@ -11,24 +11,17 @@
NOLOCALE=1
. /etc/init.d/functions
-runcmd() {
+action() {
echo -n "$1 "
shift
if [ "$BOOTUP" = "color" ]; then
- $* && echo_success || echo_failure
+ "$@" && echo_success || echo_failure
else
- $*
+ "$@"
fi
echo
}
-halt_get_remaining() {
- awk '$2 ~ /^\/$|^\/proc|^\/dev/{next}
- $3 == "tmpfs" || $3 == "proc" {print $2 ; next}
- /(^#|loopfs|autofs|sysfs|^none|^\/dev\/ram|^\/dev\/root)/ {next}
- {print $2}' /proc/mounts
-}
-
# See how we were called.
case "$0" in
*halt)
@@ -57,9 +50,9 @@ esac
# Kill all processes.
[ "${BASH+bash}" = bash ] && enable kill
-runcmd $"Sending all processes the TERM signal..." /sbin/killall5 -15
+action $"Sending all processes the TERM signal..." /sbin/killall5 -15
sleep 5
-runcmd $"Sending all processes the KILL signal..." /sbin/killall5 -9
+action $"Sending all processes the KILL signal..." /sbin/killall5 -9
# Write to wtmp file before unmounting /var
/sbin/halt -w
@@ -67,13 +60,13 @@ runcmd $"Sending all processes the KILL signal..." /sbin/killall5 -9
# Save mixer settings, here for lack of a better place.
grep -q "\(alsa\)" /proc/devices
if [ $? = 0 -a -x /usr/sbin/alsactl ]; then
- runcmd $"Saving mixer settings" alsactl store
+ action $"Saving mixer settings" alsactl store
fi
# Save random seed
touch /var/lib/random-seed
chmod 600 /var/lib/random-seed
-runcmd $"Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null
+action $"Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null
# Sync the system clock.
ARC=0
@@ -118,87 +111,38 @@ case "$SRM" in
;;
esac
-runcmd $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
+action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
# Try to unmount tmpfs filesystems to avoid swapping them in. Ignore failures.
tmpfs=$(awk '$2 ~ /^\/($|proc|dev)/ { next; }
$3 == "tmpfs" { print $2; }' /proc/mounts | sort -r)
-[ -n "$tmpfs" ] && umount $tmpfs 2>/dev/null
+[ -n "$tmpfs" ] && fstab-decode umount $tmpfs 2>/dev/null
# Turn off swap, then unmount file systems.
[ -f /proc/swaps ] && SWAPS=`awk '! /^Filename/ { print $1 }' /proc/swaps`
-[ -n "$SWAPS" ] && runcmd $"Turning off swap: " swapoff $SWAPS
+[ -n "$SWAPS" ] && action $"Turning off swap: " swapoff $SWAPS
-[ -x /sbin/quotaoff ] && runcmd $"Turning off quotas: " /sbin/quotaoff -aug
+[ -x /sbin/quotaoff ] && action $"Turning off quotas: " /sbin/quotaoff -aug
# Unmount file systems, killing processes if we have to.
# Unmount loopback stuff first
-remaining=`awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts`
-devremaining=`awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts`
-[ -n "$remaining" ] && {
- sig=
- retry=3
- while [ -n "$remaining" -a "$retry" -gt 0 ]
- do
- if [ "$retry" -lt 3 ]; then
- runcmd $"Unmounting loopback filesystems (retry):" umount $remaining
- else
- runcmd $"Unmounting loopback filesystems: " umount $remaining
- fi
- for dev in $devremaining ; do
- losetup $dev > /dev/null 2>&1 && \
- runcmd $"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
- /sbin/fuser -k -m $sig $remaining >/dev/null
- sleep 5
- retry=$(($retry -1))
- sig=-9
- done
-}
+__umount_loopback_loop
# Unmount RPC pipe file systems
-sig=
-retry=3
-remaining=`awk '$3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' /proc/mounts`
-
-while [ -n "$remaining" -a "$retry" -gt 0 ]
-do
- if [ "$retry" -lt 3 ]; then
- runcmd $"Unmounting pipe file systems (retry): " umount -f $remaining
- else
- runcmd $"Unmounting pipe file systems: " umount -f $remaining
- fi
- sleep 2
- remaining=`awk '$3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' /proc/mounts`
- [ -z "$remaining" ] && break
- /sbin/fuser -k -m $sig $remaining >/dev/null
- sleep 5
- retry=$(($retry-1))
- sig=-9
-done
-
-sig=
-retry=3
-remaining=`halt_get_remaining | sort -r`
+__umount_loop '$3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' \
+ /proc/mounts \
+ $"Unmounting pipe file systems: " \
+ $"Unmounting pipe file systems (retry): " \
+ -f
+
+LANG=C __umount_loop '$2 ~ /^\/$|^\/proc|^\/dev/{next}
+ $3 == "tmpfs" || $3 == "proc" {print $2 ; next}
+ /(loopfs|autofs|sysfs|^none|^\/dev\/ram|^\/dev\/root)/ {next}
+ {print $2}' /proc/mounts \
+ $"Unmounting file systems: " \
+ $"Unmounting file systems (retry): " \
+ -f
-while [ -n "$remaining" -a "$retry" -gt 0 ]
-do
- if [ "$retry" -lt 3 ]; then
- LANG=C runcmd $"Unmounting file systems (retry): " umount -f $remaining
- else
- LANG=C runcmd $"Unmounting file systems: " umount -f $remaining
- fi
- sleep 2
- remaining=`halt_get_remaining | sort -r`
- [ -z "$remaining" ] && break
- /sbin/fuser -k -m $sig $remaining >/dev/null
- sleep 5
- retry=$(($retry-1))
- sig=-9
-done
[ -f /proc/bus/usb/devices ] && umount /proc/bus/usb
# remove the crash indicator flag
@@ -207,7 +151,7 @@ rm -f /.autofsck
# Try all file systems other than root and RAM disks, one last time.
mount | awk '!/( \/ |^\/dev\/root|^\/dev\/ram| \/proc )/ { print $3 }' | sort -r | \
while read line; do
- umount -f $line
+ fstab-decode umount -f $line
done
if [ -x /sbin/halt.local ]; then
@@ -217,7 +161,7 @@ fi
# Remount read only anything that's left mounted.
# echo $"Remounting remaining filesystems readonly"
mount | awk '{ print $3 }' | while read line; do
- mount -n -o ro,remount $line
+ fstab-decode mount -n -o ro,remount $line
done
# Now halt or reboot.