aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d/init.d/functions
diff options
context:
space:
mode:
Diffstat (limited to 'rc.d/init.d/functions')
-rw-r--r--rc.d/init.d/functions414
1 files changed, 34 insertions, 380 deletions
diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions
index 48fa2c01..33f9eb20 100644
--- a/rc.d/init.d/functions
+++ b/rc.d/init.d/functions
@@ -61,7 +61,14 @@ systemctl_redirect () {
}
-[ -z "${CONSOLETYPE:-}" ] && CONSOLETYPE="$(/sbin/consoletype <&2)"
+if [ -z "${CONSOLETYPE:-}" ]; then
+ if [ -c "/dev/stderr" -a -r "/dev/stderr" ]; then
+ CONSOLETYPE="$(/sbin/consoletype < /dev/stderr 2>/dev/null)"
+ else
+ CONSOLETYPE="serial"
+ fi
+fi
+
# Get a sane screen width, and default to 80 when exact info not available
[ -z "${COLUMNS:-}" ] && COLUMNS=`stty -a 2>/dev/null | sed -n 's/.*columns \([0-9]*\);.*/\1/p'`
[ -z "${COLUMNS:-}" ] && COLUMNS=80
@@ -176,11 +183,6 @@ inmyroot() {
}
-# Interpret escape sequences in an fstab entry
-fstab_decode_str() {
- fstab-decode echo "$1"
-}
-
# Check if any of $pid (could be plural) are running
checkpid() {
local i
@@ -191,82 +193,6 @@ checkpid() {
return 1
}
-__readlink() {
- ls -bl "$@" 2>/dev/null| awk '{ print $NF }'
-}
-
-__fgrep() {
- s=$1
- f=$2
- while read line; do
- if strstr "$line" "$s"; then
- echo $line
- return 0
- fi
- done < $f
- return 1
-}
-
-# __umount_loop awk_program fstab_file first_msg retry_msg retry_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=-15
- local retry=3 count
-
- 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 $remaining
- else
- action "$4" fstab-decode umount $5 $remaining
- fi
- count=4
- remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
- while [ "$count" -gt 0 ]; do
- [ -z "$remaining" ] && break
- count=$(($count-1))
- usleep 500000
- remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
- done
- [ -z "$remaining" ] && break
- fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null
- sleep 3
- retry=$(($retry -1))
- sig=-9
- done
-}
-
-# Similar to __umount loop above, specialized for loopback devices
-__umount_loopback_loop() {
- local remaining devremaining sig=-15
- local retry=3
-
- remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" && $2 !~ /^\/live\// {print $2}' /proc/mounts)
- devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" && $2 !~ /^\/live\// {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 %s: " $dev \
- losetup -d $dev
- done
- remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" && $2 !~ /^\/live\// {print $2}' /proc/mounts)
- devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" && $2 !~ /^\/live\// {print $1}' /proc/mounts)
- [ -z "$remaining" ] && break
- fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null
- sleep 3
- 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.
@@ -398,7 +324,7 @@ daemon() {
killproc() {
local RC killlevel= base pid pid_file= delay try
- RC=0; delay=3
+ RC=0; delay=3; try=0
# Test syntax.
if [ "$#" -eq 0 ]; then
gprintf "Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]"
@@ -409,7 +335,11 @@ killproc() {
shift 2
fi
if [ "$1" = "-d" ]; then
- delay=$2
+ delay=$(echo $2 | awk -v RS=' ' -v IGNORECASE=1 '{if($1!~/^[0-9.]+[smhd]?$/) exit 1;d=$1~/s$|^[0-9.]*$/?1:$1~/m$/?60:$1~/h$/?60*60:$1~/d$/?24*60*60:-1;if(d==-1) exit 1;delay+=d*$1} END {printf("%d",delay+0.5)}')
+ if [ "$?" -eq 1 ]; then
+ echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]"
+ return 1
+ fi
shift 2
fi
@@ -697,121 +627,6 @@ strstr() {
return 0
}
-
-# Confirm whether we really want to run this service
-confirm() {
- gprintf "Start service %s (Y)es/(N)o/(C)ontinue? [Y] \n" $1
- local YES=`gprintf "yY"`
- local NOT=`gprintf "nN"`
- local CNT=`gprintf "cC"`
- read answer
-
- if strstr "$YES" "$answer" || [ "$answer" = "" ] ; then
- return 0
- elif strstr "$CNT" "$answer" ; then
- return 2
- elif strstr "$NOT" "$answer" ; then
- return 1
- fi
- confirm $*
-}
-
-initsplash() {
- [[ -f /etc/sysconfig/bootsplash ]] && source /etc/sysconfig/bootsplash
- [[ -n $SPLASH ]] && splash_rc=$SPLASH
- [[ -x /sbin/plymouthd ]] || splash_rc=no
- if [ -x /sbin/plymouthd ]; then
- splash_mode=plymouth
- if [ -r /proc/cmdline ] && grep -q splash /proc/cmdline && [ "$splash_rc" != "no" ]; then
- splash_rc=yes
- else
- splash_rc=no
- /bin/plymouth quit 2>/dev/null
- PLYMOUTH=
- fi
- else
- splash_rc=no
- fi
-
- [[ $splash_rc != "no" && $splash_rc != "No" && $splash_rc != "NO" ]] && export splash_rc=yes
- [[ $splash_mode = "plymouth" ]] || splash_rc=
- if [[ -z "$1" ]]; then
- set `/sbin/runlevel`
- __runlevel=$2
- __previous=$1
- else
- __runlevel=$1
- __previous=N
- fi
- [ "$splash_mode" = "plymouth" -a "$splash_rc" = "yes" -a -e /sys/class/graphics/fb0 ] && [ "$__runlevel" = 0 -o "$__runlevel" = 6 ] && /sbin/plymouthd --mode=shutdown
- export splash_mode splash_rc
-}
-
-rc_splash() {
- [[ "$splash_rc" = "yes" ]] || return
- if [ "$splash_mode" = "plymouth" ]; then
- if [ "$1" = "start" ]; then
- /bin/plymouth --show-splash 2>/dev/null
- if [ "$2" = "1" ]; then
- /bin/plymouth message --text="`OUTPUT_CHARSET=UTF-8 gprintf 'Booting the system... Press Esc for verbose mode.'`" 2> /dev/null
- elif [ "$2" = "0" ]; then
- /bin/plymouth message --text="`OUTPUT_CHARSET=UTF-8 gprintf 'Shutting down the system... Press Esc for verbose mode.'`" 2> /dev/null
- else
- /bin/plymouth message --text="`OUTPUT_CHARSET=UTF-8 gprintf 'Restarting the system... Press Esc for verbose mode.'`" 2> /dev/null
- fi
- elif [ "$1" = "stop" -o "$1" = "exit" ]; then
- /bin/plymouth quit 2>/dev/null
- elif [ "$1" = "umount" ]; then
- /bin/plymouth quit --retain-splash 2>/dev/null
- elif [ "$1" = "verbose" ]; then
- /bin/plymouth --hide-splash 2>/dev/null
- else
- /bin/plymouth --update "$1" 2>/dev/null
- fi
- fi
-}
-
-#
-# This function finds the encoding of the current locale (it can
-# be overwritten by a "CHARSET" variable if needed); the call
-# to "locale charmap" should return the proper value; in case it
-# fails, a guess from the locale name is done.
-# this function is also defined in setsysfont script
-# if you change it here change it there too, to have the same behaviour
-#
-get_locale_encoding() {
- CHARSET=${CHARSET=`LC_ALL=$GP_LANG locale charmap 2> /dev/null`}
- case "$CHARSET" in
- ANSI_X3.4-1968)
- # this means that the locale has not been
- # correctly initialized; we will look at the
- # locale naming and use the known
- # default values for various languages
- case "${LC_ALL}${LC_CTYPE}${LANG}" in
- # the locale tells it is in UTF-8, or it is a language
- # we know must be in UTF-8 by default
- *.utf8*|*.UTF-8*| \
- am*|an*|ar*|as*|az*|bn*|cy*|eo*|fa*|gn*|gu*|he*|hi*|hy*| \
- id*|ka*|kn*|ku*|ky*|lo*|m*|ne*|om*|pa*|ph*|se*|sr*|st*| \
- ta*|te*|tg*|ti*|tk*|tl*|tt*|ug*|ur*|uz*|vi*|xh*|y*)
- CHARSET="UTF-8" ;;
- esac
- ;;
- esac
- echo "$CHARSET"
-}
-
-# resolve a device node to its major:minor numbers in decimal or hex
-get_numeric_dev() {
-(
- fmt="%d:%d"
- if [ "$1" = "hex" ]; then
- fmt="%x:%x"
- fi
- ls -lH "$2" | awk '{ sub(/,/, "", $5); printf("'"$fmt"'", $5, $6); }'
-) 2>/dev/null
-}
-
# Check whether file $1 is a backup or rpm-generated file and should be ignored
is_ignored_file() {
case "$1" in
@@ -844,187 +659,26 @@ is_false() {
# Apply sysctl settings, including files in /etc/sysctl.d
apply_sysctl() {
- sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1
- for file in /etc/sysctl.d/* ; do
- is_ignored_file "$file" && continue
- test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1
- done
-}
-
-key_is_random() {
- [ "$1" = "/dev/urandom" -o "$1" = "/dev/hw_random" \
- -o "$1" = "/dev/random" ]
-}
-
-find_crypto_mount_point() {
- local fs_spec fs_file fs_vfstype remaining_fields
- local fs
- while read fs_spec fs_file remaining_fields; do
- if [ "$fs_spec" = "/dev/mapper/$1" ]; then
- echo $fs_file
- break;
- fi
- done < /etc/fstab
-}
-
-# Because of a chicken/egg problem, init_crypto must be run twice. /var may be
-# encrypted but /var/lib/random-seed is needed to initialize swap.
-init_crypto() {
- local have_random dst src key opt lsl owner params makeswap skip arg opt
- local param value rc ret mke2fs mdir prompt mount_point
-
- ret=0
- have_random=$1
- while read dst src key opt; do
- [ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue
- [ -b "/dev/mapper/$dst" ] && continue;
- if [ "$have_random" = 0 ] && key_is_random "$key"; then
- continue
- fi
- if [ -n "$key" -a "x$key" != "xnone" ]; then
- if test -e "$key" ; then
- owner=$(ls -l $key | (read a b owner rest; echo $owner))
- if ! key_is_random "$key"; then
- lsl=$(ls -l "$key")
- if [ "${lsl:4:6}" != "------" ]; then
- gprintf "INSECURE MODE FOR %s\n" $key
- fi
- fi
- if [ "$owner" != root ]; then
- gprintf "INSECURE OWNER FOR %s\n" $key
- fi
- else
- gprintf "Key file for %s not found, skipping\n" $dst
- ret=1
- continue
- fi
- else
- key=""
- fi
- params=""
- makeswap=""
- mke2fs=""
- skip=""
- # Parse the src field for UUID= and convert to real device names
- if [ "${src%%=*}" == "UUID" ]; then
- src=$(/sbin/blkid -t "$src" -l -o device)
- elif [ "${src/^\/dev\/disk\/by-uuid\/}" != "$src" ]; then
- src=$(__readlink $src)
- fi
- # Is it a block device?
- [ -b "$src" ] || continue
- # Is it already a device mapper slave? (this is gross)
- devesc=${src##/dev/}
- devesc=${devesc//\//!}
- for d in /sys/block/dm-*/slaves ; do
- [ -e $d/$devesc ] && continue 2
- done
- # Parse the options field, convert to cryptsetup parameters and
- # contruct the command line
- while [ -n "$opt" ]; do
- arg=${opt%%,*}
- opt=${opt##$arg}
- opt=${opt##,}
- param=${arg%%=*}
- value=${arg##$param=}
-
- case "$param" in
- cipher)
- params="$params -c $value"
- if [ -z "$value" ]; then
- gprintf "%s: no value for cipher option, skipping\n" $dst
- skip="yes"
- fi
- ;;
- size)
- params="$params -s $value"
- if [ -z "$value" ]; then
- gprintf "%s: no value for size option, skipping\n" $dst
- skip="yes"
- fi
- ;;
- hash)
- params="$params -h $value"
- if [ -z "$value" ]; then
- gprintf "%s: no value for hash option, skipping\n" $dst
- skip="yes"
- fi
- ;;
- noauto)
- skip="yes"
- ;;
- verify)
- params="$params -y"
- ;;
- swap)
- makeswap=yes
- ;;
- tmp)
- mke2fs=yes
- esac
- done
- if [ "$skip" = "yes" ]; then
- ret=1
- continue
- fi
- if [ -z "$makeswap" ] && cryptsetup isLuks "$src" 2>/dev/null ; then
- if key_is_random "$key"; then
- gprintf "%s: LUKS requires non-random key, skipping\n" $dst
- ret=1
- continue
- fi
- if [ -n "$params" ]; then
- echo "$dst: options are invalid for LUKS partitions," \
- "ignoring them"
- fi
- if [ -n "$key" ]; then
- /sbin/cryptsetup -d $key luksOpen "$src" "$dst" <&1 2>/dev/null && success || failure
- rc=$?
- else
- mount_point="$(find_crypto_mount_point $dst)"
- [ -n "$mount_point" ] || mount_point=${src##*/}
- prompt=$(printf $"%s is password protected" "$mount_point")
- if [ "$splash_rc" = yes ] && [ -d /usr/share/plymouth ]; then
- plymouth ask-for-password --prompt "$prompt" --command="/sbin/cryptsetup luksOpen -T1 $src $dst" --number-of-tries=3 <&1
- rc=$?
- else
- # stop splash to ask for password
- rc_splash verbose
- /sbin/cryptsetup luksOpen "$src" "$dst" <&1 && success || failure
- rc=$?
- fi
- fi
- else
- if [ -z "$key" ]; then
- mount_point="$(find_crypto_mount_point $dst)"
- [ -n "$mount_point" ] || mount_point=${src##*/}
- prompt=$(printf $"%s is password protected" "$mount_point")
- plymouth ask-for-password --prompt "$prompt" --command="/sbin/cryptsetup $params create $dst $src" <&1
- rc=$?
- else
- /sbin/cryptsetup $params ${key:+-d $key} create "$dst" "$src" <&1 2>/dev/null && success || failure
- rc=$?
- fi
- fi
- if [ $rc -ne 0 ]; then
- ret=1
- continue
- fi
- if [ -b "/dev/mapper/$dst" ]; then
- if [ "$makeswap" = "yes" ]; then
- mkswap "/dev/mapper/$dst" 2>/dev/null >/dev/null
- fi
- if [ "$mke2fs" = "yes" ]; then
- if mke2fs "/dev/mapper/$dst" 2>/dev/null >/dev/null \
- && mdir=$(mktemp -d /tmp/mountXXXXXX); then
- mount "/dev/mapper/$dst" "$mdir" && chmod 1777 "$mdir"
- umount "$mdir"
- rmdir "$mdir"
- fi
- fi
- fi
- done < /etc/crypttab
- return $ret
+ if [ -x /lib/systemd/systemd-sysctl ]; then
+ /lib/systemd/systemd-sysctl
+ else
+ for file in /usr/lib/sysctl.d/*.conf ; do
+ is_ignored_file "$file" && continue
+ [ -f /run/sysctl.d/${file##*/} ] && continue
+ [ -f /etc/sysctl.d/${file##*/} ] && continue
+ test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1
+ done
+ for file in /run/sysctl.d/*.conf ; do
+ is_ignored_file "$file" && continue
+ [ -f /etc/sysctl.d/${file##*/} ] && continue
+ test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1
+ done
+ for file in /etc/sysctl.d/*.conf ; do
+ is_ignored_file "$file" && continue
+ test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1
+ done
+ sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1
+ fi
}
# A sed expression to filter out the files that is_ignored_file recognizes