1 #!/bin/sh - keep it for file(1) to get bourne shell script result
2 # functions This file contains functions to be used by most or all
3 # shell scripts in the /etc/rc.d/init.d directory.
6 # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
7 # Hacked by: Greg Galloway and Marc Ewing
8 # Modified for PLD Linux by:
9 # Marek Obuchowicz <elephant@pld-linux.org>
10 # Arkadiusz Miśkiewicz <misiek@pld-linux.org>
11 # Michał Kochanowicz <mkochano@pld-linux.org>
12 # Łukasz Pawelczyk <havner@pld-linux.org>
13 # Modified for TLD Linux by:
14 # Marcin Krol <hawk@tld-linux.org>
16 # First set up a default search path.
17 export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
20 if [ -z "$COLUMNS" -o -z "$LINES" ]; then
22 set -- $(stty size 2>/dev/null)
24 COLUMNS=${COLUMNS:-$2}
29 [ -z "$LINES" ] || [ "$LINES" -le 0 ] && LINES=40
30 [ -z "$COLUMNS" ] || [ "$COLUMNS" -le 0 ] && COLUMNS=80
32 INIT_COL=$((COLUMNS - 13))
43 # Bold definition (second parameter to termput setaf)
47 CBRACKETS="$CYAN" # brackets [ ] color
48 CDONE="$GREEN" # DONE and WORK color
49 CBUSY="$MAGENTA" # BUSY color
50 CFAIL="$RED" # FAIL and DIED color
51 CPOWEREDBY="$CYAN" # "Powered by" color
52 CTLD="$GREEN" # "TLD Linux" color
53 CI="$RED" # Capital I color (press I to enter interactive startup)
54 CRESMAN="$GREEN" # "Resource Manager" color
55 CHARS="" # Characters displayed on the beginning of show line
56 CCHARS="$NORMAL" # Color of these characters (look at /etc/sysconfig/init-colors.gentoo example)
58 # Source configuration if available - may override default values
59 [ -r /etc/sysconfig/init-colors ] && . /etc/sysconfig/init-colors
60 [ -r /etc/sysconfig/system ] && . /etc/sysconfig/system
61 [ -r /etc/sysconfig/bootsplash ] && . /etc/sysconfig/bootsplash
63 if [ -z "$VSERVER" -o "$VSERVER" = "detect" ]; then
65 while read _f _ctx; do
66 [ "$_f" = "VxID:" -o "$_f" = "s_context:" ] && break
67 done </proc/self/status
69 if [ -z "$_ctx" -o "$_ctx" = "0" ]; then
77 # VSERVER_ISOLATION_NET = isolation only inside of vserver guests
78 if [ -z "$VSERVER_ISOLATION_NET" -o "$VSERVER_ISOLATION_NET" = "detect" ]; then
79 VSERVER_ISOLATION_NET=no
80 if [ "$VSERVER" = "yes" ]; then
81 if [ -f /proc/self/nsproxy ]; then
84 while read _t _data; do
85 [ "$_t" = "net:" ] && break
86 done < /proc/self/nsproxy
88 if [ "${_data##*\(}" = "I)" ]; then
89 VSERVER_ISOLATION_NET=yes
91 elif [ -f /proc/self/ninfo ]; then
94 while read _t _data; do
95 [ "$_t" = "NCaps:" ] && break
96 done < /proc/self/ninfo
98 if [ "${_t}" = "NCaps:" ]; then
99 VSERVER_ISOLATION_NET=yes
102 # assume (very?) old kernel mode
103 VSERVER_ISOLATION_NET=yes
109 # we need to know in functions if we were called from a terminal
110 if [ -z "$ISATTY" ]; then
111 [ -t ] && ISATTY=yes || ISATTY=no
118 msg_usage " is_yes {value}"
124 yes|Yes|YES|true|True|TRUE|on|On|ON|Y|y|1)
138 msg_usage " is_no {value}"
143 no|No|NO|false|False|FALSE|off|Off|OFF|N|n|0)
154 # checks if file is empty
155 # empty lines and lines beginning with hash are ignored
157 [ -s "$1" ] || return 0
158 grep -vqE "^(#|[[:blank:]]*$)" "$1" && return 1 || return 0
161 # returns OK if $1 contains $2
163 [ "${1#*$2*}" = "$1" ] && return 1
167 # Apply sysctl settings, including files in /etc/sysctl.d
170 for file in /etc/sysctl.d/*.conf; do
171 test -f "$file" && sysctl -q -e -p "$file"
173 sysctl -q -e -p /etc/sysctl.conf
176 if is_yes "$FASTRC" || is_yes "$IN_SHUTDOWN"; then
180 if is_no "$RC_LOGGING"; then
183 while [ "$1" != "${1##-}" ]; do
201 local _x _y _z v v1 old_IFS ver
205 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
214 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
216 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
218 while [ ${#ver} -lt 9 ]; do ver="0$ver"; done
224 local _x _y _z v v1 old_IFS ver
228 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
236 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
238 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
244 local _x _y _z v v1 old_IFS ver
248 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
256 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
263 is_yes "$ISATTY" || return
265 if is_yes "$FASTRC" || is_no "$TPUT"; then
268 echo -ne "\033[$(($2+1))G"
271 echo -ne "\033[${2}A"
283 is_yes "$COLOR_INIT" && echo -ne "\033[${ISBOLD};3${2}m"
286 termput setaf $NORMAL
295 if [ "$3" = "1" ]; then tput bold; else tput sgr0; fi
296 is_yes "$COLOR_INIT" && tput setaf "$2"
299 termput setaf $NORMAL
305 if [ ! -x /bin/printf ]; then
307 # FIXME: buggy when single or double quotes in message!
312 if [ $# -gt 0 ]; then
315 while [ $# -gt 0 ]; do
320 awk "BEGIN {printf \"$text\", \"$m\"; }"
324 # National language support function
326 local msg_echo nls_domain text message
328 nls_domain="$NLS_DOMAIN"
329 while [ "$1" != "${1##-}" ]; do
345 # empty message, so we return --misiek
346 if [ -z "$message" ]; then
351 if is_yes "$GETTEXT"; then
352 message=$(TEXTDOMAINDIR="/etc/sysconfig/locale" gettext -e --domain="${nls_domain:-rc-scripts}" "$message")
355 printf "$message" "$@"
362 if ! is_no "$BOOT_SPLASH" && ! is_yes "$VSERVER"; then
363 [ -x /bin/splash ] && /bin/splash "$action"
370 nls "ERROR: Networking is down. %s can't be run." "$1" >&2
374 show "Starting %s service" "$1"
377 msg_already_running() {
378 nls "%s service is already running." "$1"
382 show "Stopping %s service" "$1"
386 nls "%s service is not running." "$1"
390 show "Reloading %s service" "$1"
397 # Some functions to handle TLD Linux-style messages
401 if is_yes "$RC_UPTIME"; then
402 time=$(awk '{printf("[%8.2f] ", $1)}' /proc/uptime)
405 if is_no "$FASTRC" && is_yes "$GETTEXT"; then
406 text=$time$(nls -n "$@")
408 text=$time$(printf "$@")
411 while [ $((len++)) -lt $INIT_COL ]; do
414 if [ -n "$CHARS" ]; then
415 termput setaf $CCHARS
423 termput hpa $INIT_COL
426 # Displays message in square brackests ("[ DONE ]"). Takes two arguments.
427 # First is the text to display, second is color number to use (argument to
428 # tput setaf). If second argument is not given, default (2, green) will be
438 echo -n "$(termput setaf $CBRACKETS)[$(termput setaf $COLOR) $(nls --nls-domain rc-scripts "$1") $(termput setaf $CBRACKETS)]$(termput op)"
463 # Check if $pid (could be plural) are running
466 [ -d "/proc/$1" ] && return 0
472 # - outside chroot get only those processes, which are outside chroot.
473 # - inside chroot get only those processes, which are inside chroot.
474 # - don't filter out pids which do not have corresponding running processes (process died etc)
475 # (note: some processes like named are chrooted but run outside chroot)
476 # - do nothing inside vserver
478 # no pids, exit early
479 [ $# -eq 0 ] && return
481 # filter by pid namespace if such dir exists for current process
482 # we do filter in containers as stacked containers are possible with LXC
483 if [ -d /proc/$$/ns ]; then
485 pids=$(filter_ns "$@") && set -- "$pids"
488 if is_yes "$VSERVER"; then
493 if [ $# -lt 1 -o ! -d /proc/1 ]; then
498 local root_dir good_pids="" good_add_pid
499 for root_pid in $@; do
500 root_dir=$(resolvesymlink /proc/${root_pid}/root)
501 if [ -n "$root_dir" ]; then
503 if [ -n "${SYSTEM_CHROOTS}" ]; then
504 for r_dir in ${SYSTEM_CHROOTS}; do
505 echo "$root_dir" | grep -q "^${r_dir}" && good_add_pid=0
508 [ "$good_add_pid" -eq 1 ] && good_pids="$good_pids $root_pid"
509 elif [ ! -d "/proc/$root_pid" ]; then
510 good_pids="$good_pids $root_pid"
516 # similar to filter_chroot, but filter based on /proc/PID/ns/pid value
518 local cur_ns=$(resolvesymlink /proc/$$/ns/pid)
519 [ "$cur_ns" ] || return 1
522 # add pids if it matches current pid namespace
523 # we should add pids what do not exist (dead processes),
524 # but not add pids whose namespace does not match
525 # (processes belonging to different NS do exist in /proc)
527 if [ ! -d /proc/$pid ]; then
531 ns=$(resolvesymlink /proc/$pid/ns/pid)
532 if [ "$ns" = "$cur_ns" ]; then
541 # run_cmd Message command_to_run
542 # run_cmd -a Message command_to_run
543 # run_cmd --user "username" "Message" command_to_run
545 local force_err=0 exit_code=0 errors user
546 while [ $# -gt 0 ]; do
561 local message=$1; shift
562 show "$message"; busy
566 export HOME=/tmp TMPDIR=/tmp
567 if is_no "$RC_LOGGING"; then
568 ${user:+setuidgid -s $user} eval "$@" 2>&1
570 ${user:+setuidgid -s $user} initlog -c "$*" 2>&1
574 log_success "$1 $message"
577 log_failed "$1 $message"
580 [ -n "$errors" ] && [ $exit_code -eq 1 -o $force_err -eq 1 ] && echo "$errors"
584 _daemon_set_ulimits() {
585 local opt val ksh=${KSH_VERSION:+1}
586 set -- ${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}
587 while [ $# -gt 0 ]; do
608 # A function to start a program (now it's useful on read-only filesystem too)
610 local errors="" prog="" end="" waitname="" waittime=""
612 local nice=$SERVICE_RUN_NICE_LEVEL
613 local fork user closefds redirfds pidfile makepid chdir=/
615 # NOTE: if you wonder how the shellish (by syntax) $prog works in ssd mode,
616 # then the answer is: it totally ignores $prog and uses "$@" itself.
618 while [ $# -gt 0 ]; do
621 msg_usage " daemon [--check] [--user user] [--fork] [--chdir directory] [--closefds] [--redirfds] [--waitforname procname] [--waitfortime seconds] [--pidfile file] [--makepid] [+/-nicelevel] {program} <program args>"
625 # for compatibility with redhat/mandrake
626 nls "warning: --check option is ignored!"
656 pidfile="${1#--pidfile=}"
657 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
662 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
678 if [ -n "$user" -a "$user" != "root" ]; then
679 prog="/bin/su $user -s /bin/sh -c \""
681 if [ "$fork" = "1" ]; then
682 prog="/usr/bin/setsid ${prog:-sh -c \"}"
684 # If command to execute ends with quotation mark, add remaining
685 # arguments and close quotation.
686 if [ "$prog" != "${prog%\"}" ]; then
687 prog="$prog $*$end\""
694 [ -z "$DEFAULT_SERVICE_UMASK" ] && DEFAULT_SERVICE_UMASK=022
695 [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0
700 [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS" && echo $$ > "/dev/cpuset/${SERVICE_CPUSET}/tasks"
702 umask ${SERVICE_UMASK:-$DEFAULT_SERVICE_UMASK};
703 export USER=root HOME=/tmp TMPDIR=/tmp
705 nice=${nice:-$DEFAULT_SERVICE_RUN_NICE_LEVEL}
708 # make nice level absolute, not to be dependant of nice level of shell where service started
709 nice=$(($nice - $(nice)))
711 if [ "$closefds" = 1 ]; then
715 elif [ "$redirfds" = 1 ]; then
724 if is_no "$RC_LOGGING"; then
726 if [ ! -x $prog ]; then
727 logger -t rc-scripts -p daemon.debug "daemon: Searching PATH for $prog, consider using full path in initscript"
731 if [ -x $a/$prog ]; then
740 # use setsid to detach from terminal,
741 # needs pidfile or ssd would check setsid program instead of real program
742 if [ "$pidfile" ]; then
743 set -- /usr/bin/setsid "$@"
747 /sbin/start-stop-daemon -q --start \
749 ${pidfile:+--pidfile $pidfile} \
750 ${makepid:+--make-pidfile} \
751 ${user:+--chuid $user} \
752 ${chdir:+--chdir "$chdir"} \
753 ${fork:+--background} \
754 ${SERVICE_DROPCAPS:+--dropcap $SERVICE_DROPCAPS} \
758 nice -n $nice initlog -c "$prog" 2>&1 </dev/null
762 # wait for process (or pidfile) to be created
763 if [ "$waittime" -gt 0 ]; then
764 # waitname can be empty, as if pidfile is in use, it is not relevant
765 waitproc "$waittime" "$waitname" "$pidfile"
767 log_success "$1 startup"
772 log_failed "$1 startup"
773 [ -n "$errors" ] && echo >&2 "$errors"
778 # wait (in seconds) for process (or pidfile) to be created
779 # example: waitproc 30 httpd /var/run/httpd.pid
781 local waittime=$1 procname=$2 pidfile=$3
783 local now=$(date +%s)
784 local maxtime=$(($now + $waittime))
786 if [ -z "$procname" -a -z "$pidfile" ]; then
787 msg_usage "waitproc: procname or pidfile must be specified"
791 while [ "$(date +%s)" -lt "$maxtime" ]; do
792 pid=$(pidofproc "$procname" "$pidfile")
793 [ -n "$pid" ] && break
795 # start-stop-daemon uses same delay
800 # A function to stop a program.
802 local notset killlevel base pid pidfile result delay=3 try
805 msg_usage " killproc [--pidfile|-p PIDFILE] [-d DELAY] {program} [-SIGNAME]"
809 while [ "$1" != "${1##-}" ]; do
817 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
834 # check for second arg to be kill level
841 # experimental start-stop-daemon based killing.
842 # works only with pidfile
843 if is_no "$RC_LOGGING" && [ "$pidfile" ]; then
844 local sig=${killlevel:--TERM} retry
845 # do not retry if signal is specified,
846 # as otherwise impossible to send HUP if process pid stays in pidfile.
847 # however, do retry if --waitfortime was specified
848 if [ "${killlevel+set}" = "set" ] && [ -z "$waittime" ]; then
849 # if we send HUP it's ok if process does not die
854 : ${waitretry=$(($waittime * 2))}
856 # 1. kill with $sig, wait $delay
857 # 2. kill with $sig, wait $waittime
858 # 3. kill with KILL, wait $waitretry
859 retry="--retry ${sig#-}/${delay}/${sig#-}/${waittime}/KILL/${waitretry}"
861 /sbin/start-stop-daemon -q --stop \
863 ${waitname:+--name $waitname} \
865 ${pidfile:+--pidfile $pidfile}
867 if [ "$result" -eq 0 ]; then
880 pid=$(pidofproc "$1" "$pidfile")
881 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
884 if [ -n "$pid" -a "$pid" != "$$" ] && checkpid $pid 2>&1; then
885 if [ "$notset" = "1" ]; then
886 if checkpid $pid 2>&1; then
887 # TERM first, then KILL if not dead
892 while [ $try -lt $delay ]; do
893 checkpid $pid || break
897 if checkpid $pid; then
898 # XXX: SIGKILL is sent already on 4th second!
899 # HARMFUL for example to mysqld (which is already workarounded)
906 if [ "$result" -eq 0 ]; then
908 log_failed "$1 shutdown"
911 log_success "$1 shutdown"
913 result=$(( ! $result ))
915 # use specified level only
916 if checkpid $pid > /dev/null 2>&1; then
919 if [ "$result" -eq 0 ]; then
921 log_success "$1 got $killlevel"
925 log_failed "$1 didn't get $killlevel"
930 log_failed "$1 shutdown"
935 log_failed "$1 shutdown"
939 if [ -n "$waitname" -a -n "$waittime" ]; then
943 pid=$(pidofproc "$waitname" "$pidfile")
944 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
946 while [ "$i" -lt "$waittime" ]; do
948 checkpid $pid && sleep 1 || break
952 # Remove pid file if any.
953 if [ "$notset" = "1" ]; then
954 rm -f /var/run/${base}.pid
960 # A function to find the pid of a program.
962 local pid pidfile base=${1##*/}
964 [ -n "$2" ] && pidfile="$2"
968 msg_usage " pidofproc {program}"
972 # First try pidfile or "/var/run/*.pid"
974 /*)pidfile="${pidfile}";;
975 *) pidfile="/var/run/$pidfile";;
977 if [ -f "${pidfile}" ]; then
979 for p in $(< "${pidfile}"); do
980 [ -z "$(echo "$p" | awk '{gsub(/[0-9]/,"");print;}')" ] && pid="$pid $p"
986 # Next try "pidof" if pidfile is not specified
987 if [ -z "$pid" ] && [ -z "$pidfile" ]; then
988 pid=$(pidof -o $$ -o $PPID -o %PPID -x "$1")
991 pid=$(filter_chroot $pid)
995 # status [--pidfile PIDFILE] {subsys} [{daemon}]"
997 local pid subsys daemon cpuset_msg pidfile
998 if [ "$1" = "--pidfile" -o "$1" = "-p" ]; then
1000 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
1005 daemon=${2:-$subsys}
1009 msg_usage " status [--pidfile PIDFILE] {subsys} [{daemon}]"
1013 # if pidfile specified, pid must be there
1014 if [ "$pidfile" ]; then
1015 [ -f "$pidfile" ] && read pid < $pidfile
1016 # filter_chroot does not filter out dead pids, so this extra check, see t/status-pidfile.sh
1017 if [ ! -d "/proc/$pid" ]; then
1021 pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon)
1023 pid=$(filter_chroot $pid)
1027 if [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS"; then
1028 if grep -q "$pid" "/dev/cpuset/${SERVICE_CPUSET}/tasks"; then
1029 cpuset_msg=$(nls " in cpuset %s..." "$SERVICE_CPUSET")
1031 cpuset_msg=$(nls " outside of configured cpuset %s..." "$SERVICE_CPUSET")
1034 nls "%s (pid %s) is running%s" "$daemon" "$pid" "$cpuset_msg"
1038 # Next try "/var/run/*.pid" files; if pidfile is not set
1039 local base=${daemon##*/}
1040 if [ -z "$pidfile" -a -f /var/run/${base}.pid ]; then
1041 read pid < /var/run/${base}.pid
1042 pid=$(filter_chroot $pid)
1044 nls "%s dead but pid file (%s) exists" "$subsys" /var/run/${base}.pid
1049 # See if /var/lock/subsys/$subsys exists
1050 if [ -f /var/lock/subsys/$subsys ]; then
1051 nls "daemon %s dead but subsys (%s) locked" "$daemon" "$subsys"
1054 nls "%s is stopped" "$subsys"
1058 # Confirm whether we really want to run this service
1061 nls -n "Start service %s (Y)es/(N)o/(C)ontinue? [Y] " "$1"
1080 # module is needed (ie. is requested, is available and isn't loaded already)
1082 # module name without .o at end
1083 if ! lsmod | grep -q "$1"; then
1084 if ls -1R /lib/modules/$(uname -r)/ 2> /dev/null | grep -q "^${1}.\(\|k\)o\(\|.gz\)"; then
1094 local parsed single die args foo result
1096 while is_no "$parsed"; do
1115 if is_yes "${single}"; then
1117 show "Loading %s kernel module(s)" "$foo"
1120 if [ -x /sbin/modprobe ]; then
1121 /sbin/modprobe -s $args "$@"
1127 if is_yes "${single}"; then
1129 if [ $result = "0" ]; then
1130 is_yes "$single" && ok
1133 if is_yes "$die"; then
1134 nls "Could not load %s kernel module(s)" "$@"
1141 if is_no "$RC_LOGGING"; then
1151 initlog -n $0 -s "$1 $2" -e 1
1155 initlog -n $0 -s "$1 $2" -e 2
1159 # Check if any flavor of portmapper is running
1160 check_portmapper() {
1161 if [ -x /usr/sbin/rpcinfo ]; then
1162 if /usr/sbin/rpcinfo -p localhost >/dev/null 2>/dev/null; then
1167 elif [ -z "$(pidof portmap)" -a -z "$(pidof rpcbind)" ]; then
1173 # is_fsmounted fstype mntpoint
1174 # Check if filesystem fstype is mounted on mntpoint
1179 [ -n "$fstype" -a -n "$mntpoint" ] || return 1
1181 if [ -r /proc/mounts ]; then
1182 grep -qE "[[:blank:]]$mntpoint[[:blank:]]+$fstype[[:blank:]]" /proc/mounts
1185 if [ "$(stat -L -f -c %T $mntpoint 2>/dev/null)" = "$fstype" ]; then
1193 # __umount_loop awk_program fstab_file first_msg retry_msg umount_args
1194 # awk_program should process fstab_file and return a list of fstab-encoded
1195 # paths; it doesn't have to handle comments in fstab_file.
1197 local remaining sig=
1200 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1201 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1202 if [ "$retry" -eq 3 ]; then
1203 run_cmd "$3" fstab-decode umount $5 $remaining
1205 run_cmd "$4" fstab-decode umount $5 $remaining
1208 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1209 while [ "$count" -gt 0 ]; do
1210 [ -z "$remaining" ] && break
1213 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1215 [ -z "$remaining" ] && break
1216 fstab-decode /bin/fuser -k -m $sig $remaining >/dev/null
1218 retry=$(($retry -1))
1223 # Similar to __umount loop above, specialized for loopback devices
1224 __umount_loopback_loop() {
1225 local remaining devremaining sig=
1228 remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1229 devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1230 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1231 if [ "$retry" -eq 3 ]; then
1232 run_cmd "Unmounting loopback filesystems: " \
1233 fstab-decode umount $remaining
1235 run_cmd "Unmounting loopback filesystems (retry):" \
1236 fstab-decode umount $remaining
1238 for dev in $devremaining ; do
1239 losetup $dev > /dev/null 2>&1 && \
1240 run_cmd "Detaching loopback device $dev: " \
1243 remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1244 devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1245 [ -z "$remaining" ] && break
1246 fstab-decode /bin/fuser -k -m $sig $remaining >/dev/null
1248 retry=$(($retry -1))
1254 # If we have cachefile, use it.
1255 # If we don't, create memory variables and try to save silently,
1256 local cachefile='/var/cache/rc-scripts/msg.cache'
1259 if is_yes "$ISATTY"; then
1265 # We create $check variable which is used to invalidate the cache.
1266 # The $check contains user locale and terminal.
1267 local check="$term.$LC_MESSAGES.$INIT_COL"
1269 if [ -f "$cachefile" -a "$cachefile" -nt /etc/sysconfig/system -a "$cachefile" -nt /etc/sysconfig/init-colors ]; then
1270 if . "$cachefile" 2>/dev/null; then
1271 if [ "$check" = "$_check" ]; then
1278 _busy=$(progress "BUSY" "$CBUSY")
1279 _ok=$(progress "DONE")
1280 _started=$(progress "WORK")
1281 _fail=$(progress "FAIL" "$CFAIL")
1282 _died=$(progress "DIED" "$CFAIL")
1284 # we don't use heredoc, as ksh attempts to create tempfile then
1285 (> "$cachefile" ) 2>/dev/null || return
1286 echo "_busy='$_busy';" >> "$cachefile"
1287 echo "_ok='$_ok';" >> "$cachefile"
1288 echo "_started='$_started';" >> "$cachefile"
1289 echo "_fail='$_fail';" >> "$cachefile"
1290 echo "_died='$_died';" >> "$cachefile"
1291 echo "_check='$check';" >> "$cachefile"
1295 if [ -z "$GETTEXT" ]; then
1296 if [ -x /bin/gettext -o -x /usr/bin/gettext ]; then
1303 if [ -z "$TPUT" ]; then
1304 if [ -d /usr/share/terminfo ] && [ -x /usr/bin/tput -o -x /bin/tput ]; then
1306 # check if we are on proper terminal
1307 tput longname >/dev/null 2>&1 || TPUT=no
1318 # * Local variables:
1320 # * indent-tabs-mode: notnil