aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--functions107
-rwxr-xr-xnetfs31
-rwxr-xr-xrc.multi2
-rwxr-xr-xrc.shutdown8
-rwxr-xr-xrc.single15
-rwxr-xr-xrc.sysinit31
6 files changed, 104 insertions, 90 deletions
diff --git a/functions b/functions
index bcc97c1..5bfeb77 100644
--- a/functions
+++ b/functions
@@ -20,12 +20,12 @@ calc_columns () {
USECOLOR=""
elif [[ -t 0 ]]; then
# stty will fail when stdin isn't a terminal
- STAT_COL="$(/bin/stty size)"
+ STAT_COL="$(stty size)"
# stty gives "rows cols"; strip the rows number, we just want columns
STAT_COL="${STAT_COL##* }"
- elif /bin/tput cols &>/dev/null; then
+ elif tput cols &>/dev/null; then
# is /usr/share/terminfo already mounted, and TERM recognized?
- STAT_COL=$(/bin/tput cols)
+ STAT_COL=$(tput cols)
fi
if (( STAT_COL == 0 )); then
# if output was 0 (serial console), set default width to 80
@@ -50,7 +50,7 @@ calc_columns () {
calc_columns
# disable colors on broken terminals
-TERM_COLORS="$(/bin/tput colors 2>/dev/null)"
+TERM_COLORS="$(tput colors 2>/dev/null)"
if (( $? != 3 )); then
case $TERM_COLORS in
*[!0-9]*) USECOLOR="";;
@@ -75,17 +75,17 @@ fi
# set colors
if [[ $USECOLOR = [yY][eE][sS] ]]; then
- if /bin/tput setaf 0 &>/dev/null; then
+ if tput setaf 0 &>/dev/null; then
C_CLEAR="$(tput sgr0)" # clear text
- C_MAIN="${C_CLEAR}$(/bin/tput bold)" # main text
- C_OTHER="${C_MAIN}$(/bin/tput setaf 4)" # prefix & brackets
- C_SEPARATOR="${C_MAIN}$(/bin/tput setaf 0)" # separator
- C_BUSY="${C_CLEAR}$(/bin/tput setaf 6)" # busy
- C_FAIL="${C_MAIN}$(/bin/tput setaf 1)" # failed
+ C_MAIN="${C_CLEAR}$(tput bold)" # main text
+ C_OTHER="${C_MAIN}$(tput setaf 4)" # prefix & brackets
+ C_SEPARATOR="${C_MAIN}$(tput setaf 0)" # separator
+ C_BUSY="${C_CLEAR}$(tput setaf 6)" # busy
+ C_FAIL="${C_MAIN}$(tput setaf 1)" # failed
C_DONE="${C_MAIN}" # completed
- C_BKGD="${C_MAIN}$(/bin/tput setaf 5)" # backgrounded
+ C_BKGD="${C_MAIN}$(tput setaf 5)" # backgrounded
C_H1="${C_MAIN}" # highlight text 1
- C_H2="${C_MAIN}$(/bin/tput setaf 6)" # highlight text 2
+ C_H2="${C_MAIN}$(tput setaf 6)" # highlight text 2
else
C_CLEAR="\e[m" # clear text
C_MAIN="\e[;1m" # main text
@@ -156,12 +156,10 @@ stat_die() {
status() {
stat_busy "$1"
shift
- if "$@" &>/dev/null; then
- stat_done
- return 0
- fi
- stat_fail
- return 1
+ "$@" &>/dev/null
+ local ret=$?
+ (( $ret == 0 )) && stat_done || stat_fail
+ return $ret
}
# usage : in_array( $needle, $haystack )
@@ -179,12 +177,12 @@ in_array() {
# daemons:
add_daemon() {
- [[ -d /run/daemons ]] || /bin/mkdir -p /run/daemons
+ [[ -d /run/daemons ]] || mkdir -p /run/daemons
>| /run/daemons/"$1"
}
rm_daemon() {
- /bin/rm -f /run/daemons/"$1"
+ rm -f /run/daemons/"$1"
}
ck_daemon() {
@@ -265,10 +263,10 @@ add_omit_pids() {
omit_pids+=( $@ )
}
-
-kill_everything() {
- # $1 = where we are being called from.
- # This is used to determine which hooks to run.
+# Stop all daemons
+# This function should *never* ever perform any other actions beside calling stop_daemon()!
+# It might be used by a splash system etc. to get a list of daemons to be stopped.
+stop_all_daemons() {
# Find daemons NOT in the DAEMONS array. Shut these down first
local daemon
for daemon in /run/daemons/*; do
@@ -283,20 +281,30 @@ kill_everything() {
[[ ${DAEMONS[i]} = '!'* ]] && continue
ck_daemon ${DAEMONS[i]#@} || stop_daemon ${DAEMONS[i]#@}
done
+}
+kill_all() {
# Terminate all processes
+ # and wait until killall5 reports all done or timeout
+ # Unfortunately killall5 does not support the 0 signal, so just
+ # use SIGCONT for checking (which should be ignored).
stat_busy "Sending SIGTERM To Processes"
- run_hook "$1_prekillall"
- /sbin/killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null
- /bin/sleep 5
+ local i
+ killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null
+ for (( i=0; i<20 && $?!=2; i++ )); do
+ sleep .25 # 1/4 second
+ killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null
+ done
stat_done
stat_busy "Sending SIGKILL To Processes"
- /sbin/killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null
- /bin/sleep 1
+ local i
+ killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null
+ for (( i=0; i<4 && $?!=2; i++ )); do
+ sleep .25 # 1/4 second
+ killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null
+ done
stat_done
-
- run_hook "$1_postkillall"
}
# Start/trigger UDev, load MODULES and settle UDev
@@ -305,7 +313,7 @@ udevd_modprobe() {
# This is used to determine which hooks to run.
status "Starting UDev Daemon" udevd --daemon
- run_hook "${1}_udevlaunched"
+ run_hook "$1_udevlaunched"
stat_busy "Triggering UDev uevents"
udevadm trigger --action=add --type=subsystems
@@ -319,8 +327,8 @@ udevd_modprobe() {
status "Waiting for UDev uevents to be processed" \
udevadm settle --timeout=${UDEV_TIMEOUT:-30}
- run_hook "${1}_udevsettled"
-
+ run_hook "$1_udevsettled"
+
# in case loading a module changed the display mode
calc_columns
}
@@ -329,8 +337,8 @@ activate_vgs() {
[[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return 0
# Kernel 2.6.x, LVM2 groups
stat_busy "Activating LVM2 groups"
- /sbin/modprobe -q dm-mod 2>/dev/null
- /sbin/vgchange --sysinit -a y >/dev/null
+ modprobe -q dm-mod 2>/dev/null
+ vgchange --sysinit -a y >/dev/null
(( $? == 0 )) && stat_done || stat_fail
}
@@ -360,23 +368,14 @@ read_crypttab() {
return $failed
}
-NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs"
+# Filesystem functions
+# These can be overridden/reused for customizations like shutdown/loop-fsck.
+NETFS="nfs,nfs4,smbfs,cifs,codafs,ncpfs,shfs,fuse,fuseblk,glusterfs,davfs,fuse.glusterfs"
# Check local filesystems
fsck_all() {
- [[ -x $(type -P fsck) ]] || return 0
- stat_busy "Checking Filesystems"
- FSCK_OUT=/dev/stdout
- FSCK_ERR=/dev/stdout
- FSCK_FD=
- FORCEFSCK=
- [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f"
- run_hook sysinit_prefsck
- fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR
- local -r fsckret=$?
- (( fsckret <= 1 )) && stat_done || stat_fail
- run_hook sysinit_postfsck
- return $fsckret
+ fsck -A -T -C$FSCK_FD -a -t "no${NETFS//,/,no},noopts=_netdev" $FORCEFSCK
+ return $?
}
# Single-user login and/or automatic reboot after fsck (if needed)
@@ -415,11 +414,7 @@ fsck_reboot() {
}
mount_all() {
- stat_busy "Mounting Local Filesystems"
- run_hook sysinit_premount
- mount -a -t $NETFS -O no_netdev
- run_hook sysinit_postmount
- stat_done
+ mount -a -t "nosysfs,no${NETFS//,/,no}" -O no_netdev
}
bootlogd_stop() {
@@ -496,7 +491,7 @@ set_consolefont() {
[[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP=""
local i
for i in /dev/tty[0-9]*; do
- /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \
+ setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \
$CONSOLEFONT -C ${i} &>/dev/null
done
if (( $? )); then
diff --git a/netfs b/netfs
index 2bcec6c..ea7e4eb 100755
--- a/netfs
+++ b/netfs
@@ -4,32 +4,24 @@
. /etc/rc.conf
. /etc/rc.d/functions
-rc=0
-
case "$1" in
start)
stat_busy "Mounting Network Filesystems"
- /bin/mount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs,davfs
+ mount -a -t "$NETFS"
rc=$?
- /bin/mount -a -O _netdev
- if ((rc + $? > 0)); then
- stat_fail
- else
- add_daemon netfs
- stat_done
- fi
+ mount -a -O _netdev
+ (( rc || $? )) && stat_die
+ add_daemon netfs
+ stat_done
;;
stop)
stat_busy "Unmounting Network Filesystems"
- /bin/umount -a -O _netdev
+ umount -a -O _netdev
rc=$?
- /bin/umount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs,davfs
- if ((rc + $? > 0)); then
- stat_fail
- else
- rm_daemon netfs
- stat_done
- fi
+ umount -a -t "$NETFS"
+ (( rc || $? )) && stat_die
+ rm_daemon netfs
+ stat_done
;;
restart)
$0 stop
@@ -37,7 +29,8 @@ case "$1" in
$0 start
;;
*)
- echo "usage: $0 {start|stop|restart}"
+ echo "usage: $0 {start|stop|restart}"
+ exit 1
esac
# vim: set ts=2 noet:
diff --git a/rc.multi b/rc.multi
index b801fb6..16fa83a 100755
--- a/rc.multi
+++ b/rc.multi
@@ -9,7 +9,7 @@
run_hook multi_start
# Load sysctl variables if sysctl.conf is present
-[[ -r /etc/sysctl.conf ]] && /sbin/sysctl -q -p &>/dev/null
+[[ -r /etc/sysctl.conf ]] && sysctl -q -p &>/dev/null
# Start daemons
for daemon in "${DAEMONS[@]}"; do
diff --git a/rc.shutdown b/rc.shutdown
index fe42797..ed87eec 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -17,7 +17,13 @@ echo " "
[[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown
-kill_everything shutdown
+stop_all_daemons
+
+run_hook shutdown_prekillall
+
+kill_all
+
+run_hook shutdown_postkillall
stat_busy "Saving Random Seed"
RANDOM_SEED=/var/lib/misc/random-seed
diff --git a/rc.single b/rc.single
index d630736..7a87c72 100755
--- a/rc.single
+++ b/rc.single
@@ -6,16 +6,21 @@
. /etc/rc.conf
. /etc/rc.d/functions
-export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-
run_hook single_start
if [[ $PREVLEVEL != N ]]; then
- kill_everything single
-
+
+ stop_all_daemons
+
+ run_hook single_prekillall
+
+ kill_all
+
+ run_hook single_postkillall
+
# start up our mini logger until syslog takes over
minilogd
-
+
# Start/trigger UDev, load MODULES and settle UDev
udevd_modprobe single
fi
diff --git a/rc.sysinit b/rc.sysinit
index 7b086fa..7357582 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -174,9 +174,21 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then
fi
# Check filesystems
-fsck_all
+[[ -f /forcefsck ]] || is_in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f"
+declare -r FORCEFSCK
+run_hook sysinit_prefsck
+if [[ -x $(type -P fsck) ]]; then
+ stat_busy "Checking Filesystems"
+ fsck_all >|${FSCK_OUT:-/dev/stdout} 2>|${FSCK_ERR:-/dev/stdout}
+ declare -r fsckret=$?
+ (( fsckret <= 1 )) && stat_done || stat_fail
+else
+ declare -r fsckret=0
+fi
+run_hook sysinit_postfsck
+
# Single-user login and/or automatic reboot if needed
-fsck_reboot $?
+fsck_reboot $fsckret
status "Remounting Root Read/Write" \
mount -n -o remount,rw /
@@ -193,7 +205,10 @@ if [[ ! -L /etc/mtab ]]; then
fi
# now mount all the local filesystems
-mount_all
+run_hook sysinit_premount
+status "Mounting Local Filesystems" \
+ mount_all
+run_hook sysinit_postmount
# enable monitoring of lvm2 groups, now that the filesystems are mounted rw
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] &&
@@ -212,12 +227,12 @@ RANDOM_SEED=/var/lib/misc/random-seed
cp $RANDOM_SEED /dev/urandom
stat_busy "Removing Leftover Files"
- rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.* &>/dev/null
+ rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.* /var/run/daemons &>/dev/null
[[ ! -L /var/lock ]] && rm -rf /var/lock/*
- [[ ! -L /var/run && -d /var/run ]] && find /var/run/ \! -type d -delete
- [[ ! -L /var/run && ! -L /var/run/daemons ]] &&
- rm -rf /var/run/daemons &&
+ if [[ ! -L /var/run && -d /var/run ]]; then
+ find /var/run/ \! -type d -delete
ln -s /run/daemons /var/run/daemons
+ fi
install -Tm 0664 -o root -g utmp <(:) /var/run/utmp
# Keep {x,k,g}dm happy with xorg
mkdir -m 1777 /tmp/.{X11,ICE}-unix
@@ -231,7 +246,7 @@ fi
# Flush old locale settings and set user defined locale
stat_busy "Setting Locale: ${LOCALE:=en_US}"
echo "export LANG=$LOCALE" > /etc/profile.d/locale.sh &&
- chmod 0755 /etc/profile.d/locale.sh && stat_done || stat_fail
+chmod 0755 /etc/profile.d/locale.sh && stat_done || stat_fail
if [[ ${LOCALE,,} =~ utf ]]; then
stat_busy "Setting Consoles to UTF-8 mode"