aboutsummaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
Diffstat (limited to 'functions')
-rw-r--r--functions107
1 files changed, 51 insertions, 56 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