X-Git-Url: https://git.tld-linux.org/?a=blobdiff_plain;f=lib%2Ffunctions;h=8f08dc62283bec1b0699c90d08c63f520d60033b;hb=HEAD;hp=bbdbd64cfea3a8716080d2b8fe44e16692f206d7;hpb=12e7a5b1a4ca9c8f03ee66db198426770cc84300;p=rc-scripts.git diff --git a/lib/functions b/lib/functions index bbdbd64..b4c4840 100644 --- a/lib/functions +++ b/lib/functions @@ -10,6 +10,8 @@ # Arkadiusz Miśkiewicz # Michał Kochanowicz # Łukasz Pawelczyk +# Modified for TLD Linux by: +# Marcin Krol # First set up a default search path. export PATH="/sbin:/usr/sbin:/bin:/usr/bin" @@ -37,7 +39,6 @@ BLUE=4 MAGENTA=5 CYAN=6 WHITE=7 -NORMAL=15 # Bold definition (second parameter to termput setaf) BOLD=1 NOBOLD=0 @@ -47,74 +48,17 @@ CDONE="$GREEN" # DONE and WORK color CBUSY="$MAGENTA" # BUSY color CFAIL="$RED" # FAIL and DIED color CPOWEREDBY="$CYAN" # "Powered by" color -CPLD="$GREEN" # "PLD Linux Distribution" color +CTLD="$GREEN" # "TLD Linux" color CI="$RED" # Capital I color (press I to enter interactive startup) CRESMAN="$GREEN" # "Resource Manager" color CHARS="" # Characters displayed on the beginning of show line -CCHARS="$NORMAL" # Color of these characters (look at /etc/sysconfig/init-colors.gentoo example) +CCHARS="$WHITE" # Color of these characters (look at /etc/sysconfig/init-colors.gentoo example) # Source configuration if available - may override default values [ -r /etc/sysconfig/init-colors ] && . /etc/sysconfig/init-colors [ -r /etc/sysconfig/system ] && . /etc/sysconfig/system [ -r /etc/sysconfig/bootsplash ] && . /etc/sysconfig/bootsplash -# if initscript is invoked via bash, enable RedHat/Fedora compatibility -# RC_FEDORA is "set" if enabled and "unset" when not, but it's "value" is always empty -# this is useful for inline constructs -if [ "${BASH_VERSION+set}" = "set" ]; then - RC_LOGGING=yes - FASTRC=no - RC_FEDORA= -else - unset RC_FEDORA || : -fi - -if [ -z "$VSERVER" -o "$VSERVER" = "detect" ]; then - { - while read _f _ctx; do - [ "$_f" = "VxID:" -o "$_f" = "s_context:" ] && break - done /dev/null - if [ -z "$_ctx" -o "$_ctx" = "0" ]; then - VSERVER=no - else - VSERVER=yes - fi - unset _f _ctx -fi - -# VSERVER_ISOLATION_NET = isolation only inside of vserver guests -if [ -z "$VSERVER_ISOLATION_NET" -o "$VSERVER_ISOLATION_NET" = "detect" ]; then - VSERVER_ISOLATION_NET=no - if [ "$VSERVER" = "yes" ]; then - if [ -f /proc/self/nsproxy ]; then - # older kernels - { - while read _t _data; do - [ "$_t" = "net:" ] && break - done < /proc/self/nsproxy - } 2> /dev/null - if [ "${_data##*\(}" = "I)" ]; then - VSERVER_ISOLATION_NET=yes - fi - elif [ -f /proc/self/ninfo ]; then - # newer kernels - { - while read _t _data; do - [ "$_t" = "NCaps:" ] && break - done < /proc/self/ninfo - } 2> /dev/null - if [ "${_t}" = "NCaps:" ]; then - VSERVER_ISOLATION_NET=yes - fi - else - # assume (very?) old kernel mode - VSERVER_ISOLATION_NET=yes - fi - unset _f _data - fi -fi - # we need to know in functions if we were called from a terminal if [ -z "$ISATTY" ]; then [ -t ] && ISATTY=yes || ISATTY=no @@ -175,25 +119,7 @@ strstr() { # Apply sysctl settings, including files in /etc/sysctl.d apply_sysctl() { - if [ -x /lib/systemd/systemd-sysctl ]; then - /lib/systemd/systemd-sysctl - return - fi - - local file - for file in /usr/lib/sysctl.d/*.conf; do - [ -f /run/sysctl.d/${file##*/} ] && continue - [ -f /etc/sysctl.d/${file##*/} ] && continue - test -f "$file" && sysctl -q -e -p "$file" - done - for file in /run/sysctl.d/*.conf; do - [ -f /etc/sysctl.d/${file##*/} ] && continue - test -f "$file" && sysctl -q -e -p "$file" - done - for file in /etc/sysctl.d/*.conf; do - test -f "$file" && sysctl -q -e -p "$file" - done - sysctl -q -e -p /etc/sysctl.conf + sysctl -q -e --system } if is_yes "$FASTRC" || is_yes "$IN_SHUTDOWN"; then @@ -306,7 +232,7 @@ termput() { is_yes "$COLOR_INIT" && echo -ne "\033[${ISBOLD};3${2}m" ;; op) - termput setaf $NORMAL + echo -ne "\033[0m" ;; esac else @@ -319,7 +245,7 @@ termput() { is_yes "$COLOR_INIT" && tput setaf "$2" ;; op) - termput setaf $NORMAL + tput sgr0 ;; esac fi @@ -382,7 +308,7 @@ nls() { rc_splash() { local action="$1" - if ! is_no "$BOOT_SPLASH" && ! is_yes "$VSERVER"; then + if ! is_no "$BOOT_SPLASH"; then [ -x /bin/splash ] && /bin/splash "$action" fi @@ -417,7 +343,7 @@ msg_usage() { nls "Usage: %s" "$*" } -# Some functions to handle PLD Linux-style messages +# Some functions to handle TLD Linux-style messages show() { local text len time @@ -466,7 +392,7 @@ busy() { } ok() { - echo -ne "$_ok${RC_FEDORA+\\r}${RC_FEDORA-\\n}" + echo "$_ok" } started() { @@ -474,7 +400,7 @@ started() { } fail() { - echo -ne "$_fail${RC_FEDORA+\\r}${RC_FEDORA-\\n}" + echo "$_fail" return 1 } @@ -496,7 +422,6 @@ checkpid() { # - inside chroot get only those processes, which are inside chroot. # - don't filter out pids which do not have corresponding running processes (process died etc) # (note: some processes like named are chrooted but run outside chroot) -# - do nothing inside vserver filter_chroot() { # no pids, exit early [ $# -eq 0 ] && return @@ -508,11 +433,6 @@ filter_chroot() { pids=$(filter_ns "$@") && set -- "$pids" fi - if is_yes "$VSERVER"; then - echo $@ - return - fi - if [ $# -lt 1 -o ! -d /proc/1 ]; then echo $@ return @@ -588,7 +508,7 @@ run_cmd() { cd / export HOME=/tmp TMPDIR=/tmp if is_no "$RC_LOGGING"; then - ${user:+setuidgid -s $user} "$@" 2>&1 + ${user:+setuidgid -s $user} eval "$@" 2>&1 else ${user:+setuidgid -s $user} initlog -c "$*" 2>&1 fi @@ -628,16 +548,90 @@ _daemon_set_ulimits() { done } +# inner function used by daemon(). +# do not call this directly, as it expects variables being inherited. +# also it expects to be called from subshell as it exports env. +# it expects options parsed by daemon() and command to be executed in "$@". +_daemon_exec() { + local prog="" + umask ${SERVICE_UMASK:-$DEFAULT_SERVICE_UMASK}; + export USER=root HOME=/tmp TMPDIR=/tmp + + nice=${nice:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} + nice=${nice:-0} + + # make nice level absolute, not to be dependant of nice level of shell where service started + nice=$(($nice - $(nice))) + + if [ "$closefds" = 1 ]; then + exec 1>&- + exec 2>&- + exec 0<&- + elif [ "$redirfds" = 1 ]; then + exec 1>/dev/null + exec 2>/dev/null + exec 0&1 + exec 0&1 "/dev/cpuset/${SERVICE_CPUSET}/tasks" - if errors=$( - umask ${SERVICE_UMASK:-$DEFAULT_SERVICE_UMASK}; - export USER=root HOME=/tmp TMPDIR=/tmp - - nice=${nice:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} - nice=${nice:-0} - - # make nice level absolute, not to be dependant of nice level of shell where service started - nice=$(($nice - $(nice))) - - if [ "$closefds" = 1 ]; then - exec 1>&- - exec 2>&- - exec 0<&- - elif [ "$redirfds" = 1 ]; then - exec 1>/dev/null - exec 2>/dev/null - exec 0&1 - exec 0&1 /dev/null | grep -q "^${1}.\(\|k\)o\(\|.gz\)"; then @@ -1332,35 +1263,6 @@ rc_gettext_init() { fi } -use_upstart () { - return 1 -} -emit () { - return 0 -} -is_upstart_task() { - return 1 -} -is_upstart_running() { - return 1 -} -upstart_start() { - return 1 -} -upstart_stop() { - return 1 -} -upstart_reload() { - return 0 -} -upstart_status() { - return 1 -} -_upstart_controlled() { - return 0 -} -alias upstart_controlled='_upstart_controlled $0 "$@"' - rc_gettext_init rc_cache_init