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
169 if [ -x /lib/systemd/systemd-sysctl ]; then
170 /lib/systemd/systemd-sysctl
175 for file in /usr/lib/sysctl.d/*.conf; do
176 [ -f /run/sysctl.d/${file##*/} ] && continue
177 [ -f /etc/sysctl.d/${file##*/} ] && continue
178 test -f "$file" && sysctl -q -e -p "$file"
180 for file in /run/sysctl.d/*.conf; do
181 [ -f /etc/sysctl.d/${file##*/} ] && continue
182 test -f "$file" && sysctl -q -e -p "$file"
184 for file in /etc/sysctl.d/*.conf; do
185 test -f "$file" && sysctl -q -e -p "$file"
187 sysctl -q -e -p /etc/sysctl.conf
190 if is_yes "$FASTRC" || is_yes "$IN_SHUTDOWN"; then
194 if is_no "$RC_LOGGING"; then
197 while [ "$1" != "${1##-}" ]; do
215 local _x _y _z v v1 old_IFS ver
219 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
228 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
230 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
232 while [ ${#ver} -lt 9 ]; do ver="0$ver"; done
238 local _x _y _z v v1 old_IFS ver
242 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
250 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
252 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
258 local _x _y _z v v1 old_IFS ver
262 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
270 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
277 is_yes "$ISATTY" || return
279 if is_yes "$FASTRC" || is_no "$TPUT"; then
282 echo -ne "\033[$(($2+1))G"
285 echo -ne "\033[${2}A"
297 is_yes "$COLOR_INIT" && echo -ne "\033[${ISBOLD};3${2}m"
300 termput setaf $NORMAL
309 if [ "$3" = "1" ]; then tput bold; else tput sgr0; fi
310 is_yes "$COLOR_INIT" && tput setaf "$2"
313 termput setaf $NORMAL
319 if [ ! -x /bin/printf ]; then
321 # FIXME: buggy when single or double quotes in message!
326 if [ $# -gt 0 ]; then
329 while [ $# -gt 0 ]; do
334 awk "BEGIN {printf \"$text\", \"$m\"; }"
338 # National language support function
340 local msg_echo nls_domain text message
342 nls_domain="$NLS_DOMAIN"
343 while [ "$1" != "${1##-}" ]; do
359 # empty message, so we return --misiek
360 if [ -z "$message" ]; then
365 if is_yes "$GETTEXT"; then
366 message=$(TEXTDOMAINDIR="/etc/sysconfig/locale" gettext -e --domain="${nls_domain:-rc-scripts}" "$message")
369 printf "$message" "$@"
376 if ! is_no "$BOOT_SPLASH" && ! is_yes "$VSERVER"; then
377 [ -x /bin/splash ] && /bin/splash "$action"
384 nls "ERROR: Networking is down. %s can't be run." "$1" >&2
388 show "Starting %s service" "$1"
391 msg_already_running() {
392 nls "%s service is already running." "$1"
396 show "Stopping %s service" "$1"
400 nls "%s service is not running." "$1"
404 show "Reloading %s service" "$1"
411 # Some functions to handle TLD Linux-style messages
415 if is_yes "$RC_UPTIME"; then
416 time=$(awk '{printf("[%8.2f] ", $1)}' /proc/uptime)
419 if is_no "$FASTRC" && is_yes "$GETTEXT"; then
420 text=$time$(nls -n "$@")
422 text=$time$(printf "$@")
425 while [ $((len++)) -lt $INIT_COL ]; do
428 if [ -n "$CHARS" ]; then
429 termput setaf $CCHARS
437 termput hpa $INIT_COL
440 # Displays message in square brackests ("[ DONE ]"). Takes two arguments.
441 # First is the text to display, second is color number to use (argument to
442 # tput setaf). If second argument is not given, default (2, green) will be
452 echo -n "$(termput setaf $CBRACKETS)[$(termput setaf $COLOR) $(nls --nls-domain rc-scripts "$1") $(termput setaf $CBRACKETS)]$(termput op)"
477 # Check if $pid (could be plural) are running
480 [ -d "/proc/$1" ] && return 0
486 # - outside chroot get only those processes, which are outside chroot.
487 # - inside chroot get only those processes, which are inside chroot.
488 # - don't filter out pids which do not have corresponding running processes (process died etc)
489 # (note: some processes like named are chrooted but run outside chroot)
490 # - do nothing inside vserver
492 # no pids, exit early
493 [ $# -eq 0 ] && return
495 # filter by pid namespace if such dir exists for current process
496 # we do filter in containers as stacked containers are possible with LXC
497 if [ -d /proc/$$/ns ]; then
499 pids=$(filter_ns "$@") && set -- "$pids"
502 if is_yes "$VSERVER"; then
507 if [ $# -lt 1 -o ! -d /proc/1 ]; then
512 local root_dir good_pids="" good_add_pid
513 for root_pid in $@; do
514 root_dir=$(resolvesymlink /proc/${root_pid}/root)
515 if [ -n "$root_dir" ]; then
517 if [ -n "${SYSTEM_CHROOTS}" ]; then
518 for r_dir in ${SYSTEM_CHROOTS}; do
519 echo "$root_dir" | grep -q "^${r_dir}" && good_add_pid=0
522 [ "$good_add_pid" -eq 1 ] && good_pids="$good_pids $root_pid"
523 elif [ ! -d "/proc/$root_pid" ]; then
524 good_pids="$good_pids $root_pid"
530 # similar to filter_chroot, but filter based on /proc/PID/ns/pid value
532 local cur_ns=$(resolvesymlink /proc/$$/ns/pid)
533 [ "$cur_ns" ] || return 1
536 # add pids if it matches current pid namespace
537 # we should add pids what do not exist (dead processes),
538 # but not add pids whose namespace does not match
539 # (processes belonging to different NS do exist in /proc)
541 if [ ! -d /proc/$pid ]; then
545 ns=$(resolvesymlink /proc/$pid/ns/pid)
546 if [ "$ns" = "$cur_ns" ]; then
555 # run_cmd Message command_to_run
556 # run_cmd -a Message command_to_run
557 # run_cmd --user "username" "Message" command_to_run
559 local force_err=0 exit_code=0 errors user
560 while [ $# -gt 0 ]; do
575 local message=$1; shift
576 show "$message"; busy
580 export HOME=/tmp TMPDIR=/tmp
581 if is_no "$RC_LOGGING"; then
582 ${user:+setuidgid -s $user} eval "$@" 2>&1
584 ${user:+setuidgid -s $user} initlog -c "$*" 2>&1
588 log_success "$1 $message"
591 log_failed "$1 $message"
594 [ -n "$errors" ] && [ $exit_code -eq 1 -o $force_err -eq 1 ] && echo "$errors"
598 _daemon_set_ulimits() {
599 local opt val ksh=${KSH_VERSION:+1}
600 set -- ${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}
601 while [ $# -gt 0 ]; do
622 # A function to start a program (now it's useful on read-only filesystem too)
624 local errors="" prog="" end="" waitname="" waittime=""
626 local nice=$SERVICE_RUN_NICE_LEVEL
627 local fork user closefds redirfds pidfile makepid chdir=/
629 # NOTE: if you wonder how the shellish (by syntax) $prog works in ssd mode,
630 # then the answer is: it totally ignores $prog and uses "$@" itself.
632 while [ $# -gt 0 ]; do
635 msg_usage " daemon [--check] [--user user] [--fork] [--chdir directory] [--closefds] [--redirfds] [--waitforname procname] [--waitfortime seconds] [--pidfile file] [--makepid] [+/-nicelevel] {program} <program args>"
639 # for compatibility with redhat/mandrake
640 nls "warning: --check option is ignored!"
670 pidfile="${1#--pidfile=}"
671 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
676 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
692 if [ -n "$user" -a "$user" != "root" ]; then
693 prog="/bin/su $user -s /bin/sh -c \""
695 if [ "$fork" = "1" ]; then
696 prog="/usr/bin/setsid ${prog:-sh -c \"}"
698 # If command to execute ends with quotation mark, add remaining
699 # arguments and close quotation.
700 if [ "$prog" != "${prog%\"}" ]; then
701 prog="$prog $*$end\""
708 [ -z "$DEFAULT_SERVICE_UMASK" ] && DEFAULT_SERVICE_UMASK=022
709 [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0
714 [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS" && echo $$ > "/dev/cpuset/${SERVICE_CPUSET}/tasks"
716 umask ${SERVICE_UMASK:-$DEFAULT_SERVICE_UMASK};
717 export USER=root HOME=/tmp TMPDIR=/tmp
719 nice=${nice:-$DEFAULT_SERVICE_RUN_NICE_LEVEL}
722 # make nice level absolute, not to be dependant of nice level of shell where service started
723 nice=$(($nice - $(nice)))
725 if [ "$closefds" = 1 ]; then
729 elif [ "$redirfds" = 1 ]; then
738 if is_no "$RC_LOGGING"; then
740 if [ ! -x $prog ]; then
741 logger -t rc-scripts -p daemon.debug "daemon: Searching PATH for $prog, consider using full path in initscript"
745 if [ -x $a/$prog ]; then
754 # use setsid to detach from terminal,
755 # needs pidfile or ssd would check setsid program instead of real program
756 if [ "$pidfile" ]; then
757 set -- /usr/bin/setsid "$@"
761 /sbin/start-stop-daemon -q --start \
763 ${pidfile:+--pidfile $pidfile} \
764 ${makepid:+--make-pidfile} \
765 ${user:+--chuid $user} \
766 ${chdir:+--chdir "$chdir"} \
767 ${fork:+--background} \
768 ${SERVICE_DROPCAPS:+--dropcap $SERVICE_DROPCAPS} \
772 nice -n $nice initlog -c "$prog" 2>&1 </dev/null
776 # wait for process (or pidfile) to be created
777 if [ "$waittime" -gt 0 ]; then
778 # waitname can be empty, as if pidfile is in use, it is not relevant
779 waitproc "$waittime" "$waitname" "$pidfile"
781 log_success "$1 startup"
786 log_failed "$1 startup"
787 [ -n "$errors" ] && echo >&2 "$errors"
792 # wait (in seconds) for process (or pidfile) to be created
793 # example: waitproc 30 httpd /var/run/httpd.pid
795 local waittime=$1 procname=$2 pidfile=$3
797 local now=$(date +%s)
798 local maxtime=$(($now + $waittime))
800 if [ -z "$procname" -a -z "$pidfile" ]; then
801 msg_usage "waitproc: procname or pidfile must be specified"
805 while [ "$(date +%s)" -lt "$maxtime" ]; do
806 pid=$(pidofproc "$procname" "$pidfile")
807 [ -n "$pid" ] && break
809 # start-stop-daemon uses same delay
814 # A function to stop a program.
816 local notset killlevel base pid pidfile result delay=3 try
819 msg_usage " killproc [--pidfile|-p PIDFILE] [-d DELAY] {program} [-SIGNAME]"
823 while [ "$1" != "${1##-}" ]; do
831 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
848 # check for second arg to be kill level
855 # experimental start-stop-daemon based killing.
856 # works only with pidfile
857 if is_no "$RC_LOGGING" && [ "$pidfile" ]; then
858 local sig=${killlevel:--TERM} retry
859 # do not retry if signal is specified,
860 # as otherwise impossible to send HUP if process pid stays in pidfile.
861 # however, do retry if --waitfortime was specified
862 if [ "${killlevel+set}" = "set" ] && [ -z "$waittime" ]; then
863 # if we send HUP it's ok if process does not die
868 : ${waitretry=$(($waittime * 2))}
870 # 1. kill with $sig, wait $delay
871 # 2. kill with $sig, wait $waittime
872 # 3. kill with KILL, wait $waitretry
873 retry="--retry ${sig#-}/${delay}/${sig#-}/${waittime}/KILL/${waitretry}"
875 /sbin/start-stop-daemon -q --stop \
877 ${waitname:+--name $waitname} \
879 ${pidfile:+--pidfile $pidfile}
881 if [ "$result" -eq 0 ]; then
894 pid=$(pidofproc "$1" "$pidfile")
895 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
898 if [ -n "$pid" -a "$pid" != "$$" ] && checkpid $pid 2>&1; then
899 if [ "$notset" = "1" ]; then
900 if checkpid $pid 2>&1; then
901 # TERM first, then KILL if not dead
906 while [ $try -lt $delay ]; do
907 checkpid $pid || break
911 if checkpid $pid; then
912 # XXX: SIGKILL is sent already on 4th second!
913 # HARMFUL for example to mysqld (which is already workarounded)
920 if [ "$result" -eq 0 ]; then
922 log_failed "$1 shutdown"
925 log_success "$1 shutdown"
927 result=$(( ! $result ))
929 # use specified level only
930 if checkpid $pid > /dev/null 2>&1; then
933 if [ "$result" -eq 0 ]; then
935 log_success "$1 got $killlevel"
939 log_failed "$1 didn't get $killlevel"
944 log_failed "$1 shutdown"
949 log_failed "$1 shutdown"
953 if [ -n "$waitname" -a -n "$waittime" ]; then
957 pid=$(pidofproc "$waitname" "$pidfile")
958 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
960 while [ "$i" -lt "$waittime" ]; do
962 checkpid $pid && sleep 1 || break
966 # Remove pid file if any.
967 if [ "$notset" = "1" ]; then
968 rm -f /var/run/${base}.pid
974 # A function to find the pid of a program.
976 local pid pidfile base=${1##*/}
978 [ -n "$2" ] && pidfile="$2"
982 msg_usage " pidofproc {program}"
986 # First try pidfile or "/var/run/*.pid"
988 /*)pidfile="${pidfile}";;
989 *) pidfile="/var/run/$pidfile";;
991 if [ -f "${pidfile}" ]; then
993 for p in $(< "${pidfile}"); do
994 [ -z "$(echo "$p" | awk '{gsub(/[0-9]/,"");print;}')" ] && pid="$pid $p"
998 # Next try "pidof" if pidfile is not specified
999 if [ -z "$pid" ] && [ -z "$pidfile" ]; then
1000 pid=$(pidof -o $$ -o $PPID -o %PPID -x "$1")
1003 pid=$(filter_chroot $pid)
1007 # status [--pidfile PIDFILE] {subsys} [{daemon}]"
1009 local pid subsys daemon cpuset_msg pidfile
1010 if [ "$1" = "--pidfile" -o "$1" = "-p" ]; then
1012 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
1017 daemon=${2:-$subsys}
1021 msg_usage " status [--pidfile PIDFILE] {subsys} [{daemon}]"
1025 # if pidfile specified, pid must be there
1026 if [ "$pidfile" ]; then
1027 [ -f "$pidfile" ] && read pid < $pidfile
1028 # filter_chroot does not filter out dead pids, so this extra check, see t/status-pidfile.sh
1029 if [ ! -d "/proc/$pid" ]; then
1033 pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon)
1035 pid=$(filter_chroot $pid)
1039 if [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS"; then
1040 if grep -q "$pid" "/dev/cpuset/${SERVICE_CPUSET}/tasks"; then
1041 cpuset_msg=$(nls " in cpuset %s..." "$SERVICE_CPUSET")
1043 cpuset_msg=$(nls " outside of configured cpuset %s..." "$SERVICE_CPUSET")
1046 nls "%s (pid %s) is running%s" "$daemon" "$pid" "$cpuset_msg"
1050 # Next try "/var/run/*.pid" files; if pidfile is not set
1051 local base=${daemon##*/}
1052 if [ -z "$pidfile" -a -f /var/run/${base}.pid ]; then
1053 read pid < /var/run/${base}.pid
1054 pid=$(filter_chroot $pid)
1056 nls "%s dead but pid file (%s) exists" "$subsys" /var/run/${base}.pid
1061 # See if /var/lock/subsys/$subsys exists
1062 if [ -f /var/lock/subsys/$subsys ]; then
1063 nls "daemon %s dead but subsys (%s) locked" "$daemon" "$subsys"
1066 nls "%s is stopped" "$subsys"
1070 # Confirm whether we really want to run this service
1073 nls -n "Start service %s (Y)es/(N)o/(C)ontinue? [Y] " "$1"
1092 # module is needed (ie. is requested, is available and isn't loaded already)
1094 # module name without .o at end
1095 if ! lsmod | grep -q "$1"; then
1096 if ls -1R /lib/modules/$(uname -r)/ 2> /dev/null | grep -q "^${1}.\(\|k\)o\(\|.gz\)"; then
1106 local parsed single die args foo result
1108 while is_no "$parsed"; do
1127 if is_yes "${single}"; then
1129 show "Loading %s kernel module(s)" "$foo"
1132 if [ -x /sbin/modprobe ]; then
1133 /sbin/modprobe -s $args "$@"
1139 if is_yes "${single}"; then
1141 if [ $result = "0" ]; then
1142 is_yes "$single" && ok
1145 if is_yes "$die"; then
1146 nls "Could not load %s kernel module(s)" "$@"
1153 if is_no "$RC_LOGGING"; then
1163 initlog -n $0 -s "$1 $2" -e 1
1167 initlog -n $0 -s "$1 $2" -e 2
1171 # Check if any flavor of portmapper is running
1172 check_portmapper() {
1173 if [ -x /usr/sbin/rpcinfo ]; then
1174 if /usr/sbin/rpcinfo -p localhost >/dev/null 2>/dev/null; then
1179 elif [ -z "$(pidof portmap)" -a -z "$(pidof rpcbind)" ]; then
1185 # is_fsmounted fstype mntpoint
1186 # Check if filesystem fstype is mounted on mntpoint
1191 [ -n "$fstype" -a -n "$mntpoint" ] || return 1
1193 if [ -r /proc/mounts ]; then
1194 grep -qE "[[:blank:]]$mntpoint[[:blank:]]+$fstype[[:blank:]]" /proc/mounts
1197 if [ "$(stat -L -f -c %T $mntpoint 2>/dev/null)" = "$fstype" ]; then
1205 # __umount_loop awk_program fstab_file first_msg retry_msg umount_args
1206 # awk_program should process fstab_file and return a list of fstab-encoded
1207 # paths; it doesn't have to handle comments in fstab_file.
1209 local remaining sig=
1212 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1213 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1214 if [ "$retry" -eq 3 ]; then
1215 run_cmd "$3" fstab-decode umount $5 $remaining
1217 run_cmd "$4" fstab-decode umount $5 $remaining
1220 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1221 while [ "$count" -gt 0 ]; do
1222 [ -z "$remaining" ] && break
1225 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1227 [ -z "$remaining" ] && break
1228 fstab-decode /bin/fuser -k -m $sig $remaining >/dev/null
1230 retry=$(($retry -1))
1235 # Similar to __umount loop above, specialized for loopback devices
1236 __umount_loopback_loop() {
1237 local remaining devremaining sig=
1240 remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1241 devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1242 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1243 if [ "$retry" -eq 3 ]; then
1244 run_cmd "Unmounting loopback filesystems: " \
1245 fstab-decode umount $remaining
1247 run_cmd "Unmounting loopback filesystems (retry):" \
1248 fstab-decode umount $remaining
1250 for dev in $devremaining ; do
1251 losetup $dev > /dev/null 2>&1 && \
1252 run_cmd "Detaching loopback device $dev: " \
1255 remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1256 devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1257 [ -z "$remaining" ] && break
1258 fstab-decode /bin/fuser -k -m $sig $remaining >/dev/null
1260 retry=$(($retry -1))
1266 # If we have cachefile, use it.
1267 # If we don't, create memory variables and try to save silently,
1268 local cachefile='/var/cache/rc-scripts/msg.cache'
1271 if is_yes "$ISATTY"; then
1277 # We create $check variable which is used to invalidate the cache.
1278 # The $check contains user locale and terminal.
1279 local check="$term.$LC_MESSAGES.$INIT_COL"
1281 if [ -f "$cachefile" -a "$cachefile" -nt /etc/sysconfig/system -a "$cachefile" -nt /etc/sysconfig/init-colors ]; then
1282 if . "$cachefile" 2>/dev/null; then
1283 if [ "$check" = "$_check" ]; then
1290 _busy=$(progress "BUSY" "$CBUSY")
1291 _ok=$(progress "DONE")
1292 _started=$(progress "WORK")
1293 _fail=$(progress "FAIL" "$CFAIL")
1294 _died=$(progress "DIED" "$CFAIL")
1296 # we don't use heredoc, as ksh attempts to create tempfile then
1297 (> "$cachefile" ) 2>/dev/null || return
1298 echo "_busy='$_busy';" >> "$cachefile"
1299 echo "_ok='$_ok';" >> "$cachefile"
1300 echo "_started='$_started';" >> "$cachefile"
1301 echo "_fail='$_fail';" >> "$cachefile"
1302 echo "_died='$_died';" >> "$cachefile"
1303 echo "_check='$check';" >> "$cachefile"
1307 if [ -z "$GETTEXT" ]; then
1308 if [ -x /bin/gettext -o -x /usr/bin/gettext ]; then
1315 if [ -z "$TPUT" ]; then
1316 if [ -d /usr/share/terminfo ] && [ -x /usr/bin/tput -o -x /bin/tput ]; then
1318 # check if we are on proper terminal
1319 tput longname >/dev/null 2>&1 || TPUT=no
1330 # * Local variables:
1332 # * indent-tabs-mode: notnil