aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d
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
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')
-rwxr-xr-xrc.d/init.d/functions61
-rwxr-xr-xrc.d/init.d/halt110
-rwxr-xr-xrc.d/init.d/netfs79
-rwxr-xr-xrc.d/rc.sysinit21
4 files changed, 112 insertions, 159 deletions
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
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.
diff --git a/rc.d/init.d/netfs b/rc.d/init.d/netfs
index faab107e..59693d11 100755
--- a/rc.d/init.d/netfs
+++ b/rc.d/init.d/netfs
@@ -89,71 +89,20 @@ case "$1" in
;;
stop)
# Unmount loopback stuff first
- remaining=`LC_ALL=C awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts`
- devremaining=`LC_ALL=C 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
- action $"Unmounting loopback filesystems (retry):" umount $remaining
- else
- action $"Unmounting loopback filesystems: " umount $remaining
- fi
- for dev in $devremaining ; do
- losetup $dev >/dev/null 2>&1 && \
- action $"Detaching loopback device $dev: " losetup -d $dev
- done
- remaining=`LC_ALL=C awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts`
- devremaining=`LC_ALL=C 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
- }
- [ -n "$NETDEVMTAB" ] && {
- sig=
- retry=3
- remaining=`LC_ALL=C awk '!/^#/ && $4 ~ /_netdev/ && $2 != "/" {print $2}' /etc/mtab`
- while [ -n "$remaining" -a "$retry" -gt 0 ]
- do
- if [ "$retry" -lt 3 ]; then
- action $"Unmounting network block filesystems (retry): " umount -a -O _netdev
- else
- action $"Unmounting network block filesystems: " umount -a -O _netdev
- fi
- sleep 2
- remaining=`LC_ALL=C awk '!/^#/ && $4 ~ /_netdev/ && $2 != "/" {print $2}' /etc/mtab`
- [ -z "$remaining" ] && break
- /sbin/fuser -k -m $sig $remaining >/dev/null
- sleep 5
- retry=$(($retry - 1))
- sig=-9
- done
- }
- [ -n "$NFSMTAB" ] && {
- sig=
- retry=3
- remaining=`LC_ALL=C awk '$3 ~ /^nfs/ && $2 != "/" {print $2}' /proc/mounts`
- while [ -n "$remaining" -a "$retry" -gt 0 ]
- do
- if [ "$retry" -lt 3 ]; then
- action $"Unmounting NFS filesystems (retry): " umount -f -l $remaining
- else
- action $"Unmounting NFS filesystems: " umount -f -l $remaining
- fi
- sleep 2
- remaining=`LC_ALL=C awk '$3 ~ /^nfs/ && $2 != "/" {print $2}' /proc/mounts`
- [ -z "$remaining" ] && break
- /sbin/fuser -k -m $sig $remaining >/dev/null
- sleep 5
- retry=$(($retry - 1))
- sig=-9
- done
- }
+ __umount_loopback_loop
+ if [ -n "$NETDEVMTAB" ]; then
+ __umount_loop '$4 ~ /_netdev/ && $2 != "/" {print $2}' \
+ /etc/mtab \
+ $"Unmounting network block filesystems: " \
+ $"Unmounting network block filesystems (retry): "
+ fi
+ if [ -n "$NFSMTAB" ]; then
+ __umount_loop '$3 ~ /^nfs/ && $2 != "/" {print $2}' \
+ /proc/mounts \
+ $"Unmounting NFS filesystems: " \
+ $"Unmounting NFS filesystems (retry): " \
+ "-f -l"
+ fi
[ -n "$SMBMTAB" ] && action $"Unmounting SMB filesystems: " umount -a -t smbfs
[ -n "$CIFSMTAB" ] && action $"Unmounting CIFS filesystems: " umount -a -t cifs
[ -n "$NCPMTAB" ] && action $"Unmounting NCP filesystems: " umount -a -t ncpfs
diff --git a/rc.d/rc.sysinit b/rc.d/rc.sysinit
index 96e79c82..c0195319 100755
--- a/rc.d/rc.sysinit
+++ b/rc.d/rc.sysinit
@@ -29,11 +29,11 @@ fi
. /etc/init.d/functions
# Check SELinux status
-selinuxfs=`LC_ALL=C awk '/ selinuxfs / { print $2 }' /proc/mounts`
+selinuxfs="$(fstab_decode_str `LC_ALL=C awk '/ selinuxfs / { print $2 }' /proc/mounts`)"
SELINUX_STATE=
if [ -n "$selinuxfs" ] && [ "`cat /proc/self/attr/current`" != "kernel" ]; then
- if [ -r $selinuxfs/enforce ] ; then
- SELINUX_STATE=`cat $selinuxfs/enforce`
+ if [ -r "$selinuxfs/enforce" ] ; then
+ SELINUX_STATE=`cat "$selinuxfs/enforce"`
else
# assume enforcing if you can't read it
SELINUX_STATE=1
@@ -48,7 +48,7 @@ disable_selinux() {
echo "*** Warning -- SELinux is active"
echo "*** Disabling security enforcement for system recovery."
echo "*** Run 'setenforce 1' to reenable."
- echo "0" > $selinuxfs/enforce
+ echo "0" > "$selinuxfs/enforce"
}
relabel_selinux() {
@@ -64,14 +64,14 @@ relabel_selinux() {
*** Relabelling could take a very long time, depending on file ***
*** system size and speed of hard drives. ***
"
- echo "0" > $selinuxfs/enforce
+ echo "0" > "$selinuxfs/enforce"
/sbin/fixfiles restore > /dev/null 2>&1
rm -f /.autorelabel
if [ ! -z "$REBOOTFLAG" ]; then
echo $"Automatic reboot in progress."
reboot -f
fi
- echo $SELINUX_STATE > $selinuxfs/enforce
+ echo $SELINUX_STATE > "$selinuxfs/enforce"
if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then
chvt 8
fi
@@ -431,15 +431,16 @@ if [ X"$_RUN_QUOTACHECK" = X1 -a -x /sbin/quotacheck ]; then
if [ -x /sbin/convertquota ]; then
# try to convert old quotas
for mountpt in `LC_ALL=C awk '$4 ~ /quota/{print $2}' /etc/mtab` ; do
+ mountpt="$(fstab_decode_str "$mountpt")"
if [ -f "$mountpt/quota.user" ]; then
action $"Converting old user quota files: " \
- /sbin/convertquota -u $mountpt && \
- rm -f $mountpt/quota.user
+ /sbin/convertquota -u "$mountpt" && \
+ rm -f "$mountpt/quota.user"
fi
if [ -f "$mountpt/quota.group" ]; then
action $"Converting old group quota files: " \
- /sbin/convertquota -g $mountpt && \
- rm -f $mountpt/quota.group
+ /sbin/convertquota -g "$mountpt" && \
+ rm -f "$mountpt/quota.group"
fi
done
fi