summaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
Diffstat (limited to 'functions')
-rw-r--r--functions92
1 files changed, 67 insertions, 25 deletions
diff --git a/functions b/functions
index 2cbf01e..00d1232 100644
--- a/functions
+++ b/functions
@@ -67,8 +67,14 @@ unset TZ
unset LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \
LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE \
LC_MEASUREMENT LC_IDENTIFICATION LC_ALL
-if [[ $DAEMON_LOCALE = [yY][eE][sS] && $LOCALE ]]; then
- export LANG="${LOCALE}"
+if [[ $DAEMON_LOCALE = [yY][eE][sS] ]]; then
+ LANG="${LOCALE:=C}"
+ if [ -r /etc/locale.conf ]; then
+ . /etc/locale.conf
+ fi
+ export LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \
+ LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE \
+ LC_MEASUREMENT LC_IDENTIFICATION LC_ALL
else
export LANG=C
fi
@@ -218,7 +224,7 @@ ck_depends() {
start_daemon_bkgd() {
stat_bkgd "Starting $1"
- have_daemon "$1" && (start_daemon "$1") &>/dev/null &
+ (start_daemon "$1") >/dev/null &
}
stop_daemon() {
@@ -284,35 +290,49 @@ stop_all_daemons() {
done
}
-kill_all() {
- # Terminate all processes
- # and wait until killall5 reports all done or timeout
+# $1 - signal
+# $2 - iterations
+kill_all_wait() {
+ # Send SIGTERM/SIGKILL 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"
- 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"
- 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
+ local i
+
+ killall5 -${1} ${omit_pids[@]/#/-o } &>/dev/null
+
+ for (( i=0; i<${2}; i++ )); do
+
+ sleep .25 # 1/4 second
+
+ # sending SIGCONT to processes to check if they are there
+ killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null
+
+ if (( $? == 2 )); then
+ return 0
+ fi
+ done
+
+ return 1
+}
+
+kill_all() {
+ stat_busy "Sending SIGTERM To Processes"
+ kill_all_wait 15 40
+ if (( $? == 0 )); then
+ stat_done
+ else
+ stat_fail
+ status "Sending SIGKILL To Processes" kill_all_wait 9 60
+ fi
}
# Start/trigger UDev, load MODULES and settle UDev
udevd_modprobe() {
# $1 = where we are being called from.
# This is used to determine which hooks to run.
- status "Starting UDev Daemon" udevd --daemon
+ status "Starting UDev Daemon" /lib/udev/udevd --daemon
run_hook "$1_udevlaunched"
@@ -323,7 +343,7 @@ udevd_modprobe() {
# Load modules from the MODULES array defined in rc.conf
[[ -f /proc/modules ]] && (( ${#MODULES[*]} )) &&
- status "Loading Modules" modprobe -ab "${MODULES[@]}"
+ status "Loading User-specified Modules" modprobe -ab "${MODULES[@]}"
status "Waiting for UDev uevents to be processed" \
udevadm settle --timeout=${UDEV_TIMEOUT:-30}
@@ -369,6 +389,28 @@ read_crypttab() {
return $failed
}
+set_timezone() {
+ local tz=$1 zonefile=/usr/share/zoneinfo/$tz
+
+ [[ $tz ]] || return 1
+
+ if [[ ! -e $zonefile ]]; then
+ printf "error: \`%s' is not a valid timezone\n" "$tz"
+ return 1
+ fi
+
+ if [[ -L /etc/localtime && /etc/localtime -ef $zonefile ]]; then
+ return 0
+ fi
+
+ # respect the user's decision to symlink or copy
+ if [[ -L /etc/localtime ]]; then
+ ln -sf "/usr/share/zoneinfo/$tz" /etc/localtime
+ else
+ cp --remove-destination "/usr/share/zoneinfo/$tz" /etc/localtime
+ fi
+}
+
# 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"
@@ -435,7 +477,7 @@ bootlogd_stop() {
kill $(< /run/bootlogd.pid)
rm -f /run/bootlogd.pid
sed -i -r -e 's/\^\[\[[0-9]?;?[0-9]?[0-9]?;?[0-9]?[0-9]?[ms]//g' \
- -e 's/\^\[(\[1[0-9]1|%)G//g' -e 's/\^\[\[0;1//g' /var/log/boot
+ -e 's/\^\[(\[1?[0-9]1|%)G//g' -e 's/\^\[\[0;1//g' /var/log/boot
}
###############################