1 # $NetBSD: rc.subr,v 1.67 2006/10/07 11:25:15 elad Exp $
4 # Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
7 # This code is derived from software contributed to The NetBSD Foundation
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
19 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
32 # functions used by various rc scripts
35 : ${RC_PID:=$$}; export RC_PID
38 # Operating System dependent/independent variables
41 if [ -z "${_rc_subr_loaded}" ]; then
46 SYSCTL_N="${SYSCTL} -n"
48 PROTECT="/usr/bin/protect"
50 IDCMD="if [ -x $ID ]; then $ID -un; fi"
52 JID=`$PS -p $$ -o jid=`
59 # List vars matching pattern.
63 set | { while read LINE; do
66 "$LINE"|*[!a-zA-Z0-9_]*) continue ;;
72 # set_rcvar [var] [defval] [desc]
74 # Echo or define a rc.conf(5) variable name. Global variable
77 # If no argument is specified, echo "${name}_enable".
79 # If only a var is specified, echo "${var}_enable".
81 # If var and defval are specified, the ${var} is defined as
82 # rc.conf(5) variable and the default value is ${defvar}. An
83 # optional argument $desc can also be specified to add a
84 # description for that.
91 0) echo ${name}_enable ;;
92 1) echo ${1}_enable ;;
94 debug "set_rcvar: \$$1=$2 is added" \
95 " as a rc.conf(5) variable."
97 rcvars="${rcvars# } $_var"
98 eval ${_var}_defval=\"$2\"
100 eval ${_var}_desc=\"$*\"
105 # set_rcvar_obsolete oldvar [newvar] [msg]
106 # Define obsolete variable.
107 # Global variable $rcvars_obsolete is used.
113 debug "set_rcvar_obsolete: \$$1(old) -> \$$2(new) is defined"
115 rcvars_obsolete="${rcvars_obsolete# } $1"
116 eval ${1}_newvar=\"$2\"
118 eval ${_var}_obsolete_msg=\"$*\"
122 # force_depend script [rcvar]
123 # Force a service to start. Intended for use by services
124 # to resolve dependency issues.
125 # $1 - filename of script, in /etc/rc.d, to run
126 # $2 - name of the script's rcvar (minus the _enable)
130 local _depend _dep_rcvar
133 _dep_rcvar="${2:-$1}_enable"
135 [ -n "$rc_fast" ] && ! checkyesno always_force_depends &&
136 checkyesno $_dep_rcvar && return 0
138 /etc/rc.d/${_depend} forcestatus >/dev/null 2>&1 && return 0
140 info "${name} depends on ${_depend}, which will be forced to start."
141 if ! /etc/rc.d/${_depend} forcestart; then
142 warn "Unable to force ${_depend}. It may already be running."
149 # Test $1 variable, and warn if not set to YES or NO.
150 # Return 0 if it's "yes" (et al), nonzero otherwise.
155 debug "checkyesno: $1 is set to $_value."
158 # "yes", "true", "on", or "1"
159 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
163 # "no", "false", "off", or "0"
164 [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
168 warn "\$${1} is not set properly - see rc.conf(5)."
176 # print the list in reverse order
182 _revlist="$_revfile $_revlist"
188 # If booting directly to multiuser or $always is enabled,
189 # send SIGTERM to the parent (/etc/rc) to abort the boot.
190 # Otherwise just exit.
197 # "yes", "true", "on", or "1"
198 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
205 if [ "$autoboot" = yes -o "$always" = true ]; then
206 echo "ERROR: ABORTING BOOT (sending SIGTERM to parent)!"
213 # mount_critical_filesystems type
214 # Go through the list of critical filesystems as provided in
215 # the rc.conf(5) variable $critical_filesystems_${type}, checking
216 # each one to see if it is mounted, and if it is not, mounting it.
218 mount_critical_filesystems()
220 eval _fslist=\$critical_filesystems_${1}
221 for _fs in $_fslist; do
224 while read what _on on _type type; do
225 if [ $on = $_fs ]; then
232 mount $_fs >/dev/null 2>&1
239 # check_pidfile pidfile procname [interpreter]
240 # Parses the first line of pidfile for a PID, and ensures
241 # that the process is running and matches procname.
242 # Prints the matching PID upon success, nothing otherwise.
243 # interpreter is optional; see _find_processes() for details.
250 if [ -z "$_pidfile" -o -z "$_procname" ]; then
251 err 3 'USAGE: check_pidfile pidfile procname [interpreter]'
253 if [ ! -f $_pidfile ]; then
254 debug "pid file ($_pidfile): not readable."
257 read _pid _junk < $_pidfile
258 if [ -z "$_pid" ]; then
259 debug "pid file ($_pidfile): no pid in file."
262 _find_processes $_procname ${_interpreter:-.} '-p '"$_pid"
266 # check_process procname [interpreter]
267 # Ensures that a process (or processes) named procname is running.
268 # Prints a list of matching PIDs.
269 # interpreter is optional; see _find_processes() for details.
275 if [ -z "$_procname" ]; then
276 err 3 'USAGE: check_process procname [interpreter]'
278 _find_processes $_procname ${_interpreter:-.} '-ax'
282 # _find_processes procname interpreter psargs
283 # Search for procname in the output of ps generated by psargs.
284 # Prints the PIDs of any matching processes, space separated.
286 # If interpreter == ".", check the following variations of procname
287 # against the first word of each command:
289 # `basename procname`
290 # `basename procname` + ":"
291 # "(" + `basename procname` + ")"
292 # "[" + `basename procname` + "]"
294 # If interpreter != ".", read the first line of procname, remove the
295 # leading #!, normalise whitespace, append procname, and attempt to
296 # match that against each command, either as is, or with extra words
297 # at the end. As an alternative, to deal with interpreted daemons
298 # using perl, the basename of the interpreter plus a colon is also
299 # tried as the prefix to procname.
303 if [ $# -ne 3 ]; then
304 err 3 'USAGE: _find_processes procname interpreter psargs'
311 if [ $_interpreter != "." ]; then # an interpreted script
312 _script="${_chroot}${_chroot:+/}$_procname"
313 if [ -r "$_script" ]; then
314 read _interp < $_script # read interpreter name
317 _interp=${_interp#\#!} # strip #!
321 shift # drop env to get real name
324 if [ $_interpreter != $1 ]; then
325 warn "\$command_interpreter $_interpreter != $1"
329 warn "no shebang line in $_script"
334 warn "cannot read shebang line from $_script"
337 _interp="$* $_procname" # cleanup spaces, add _procname
340 _fp_match='case "$_argv" in
341 ${_interp}|"${_interp} "*|"[${_interpbn}]"|"${_interpbn}: ${_procname}"*)'
342 else # a normal daemon
343 _procnamebn=${_procname##*/}
344 _fp_args='_arg0 _argv'
345 _fp_match='case "$_arg0" in
346 $_procname|$_procnamebn|${_procnamebn}:|"(${_procnamebn})"|"[${_procnamebn}]")'
350 $PS 2>/dev/null -o pid= -o jid= -o command= $_psargs"' |
351 while read _npid _jid '"$_fp_args"'; do
353 if [ "$JID" -eq "$_jid" ];
354 then echo -n "$_pref$_npid";
361 # debug "in _find_processes: proccheck is ($_proccheck)."
365 # sort_lite [-b] [-n] [-k POS] [-t SEP]
366 # A lite version of sort(1) (supporting a few options) that can be used
367 # before the real sort(1) is available (e.g., in scripts that run prior
368 # to mountcritremote). Requires only shell built-in functionality.
372 local funcname=sort_lite
373 local sort_sep="$IFS" sort_ignore_leading_space=
374 local sort_field=0 sort_strict_fields= sort_numeric=
375 local nitems=0 skip_leading=0 trim=
378 while getopts bnk:t: flag; do
380 b) sort_ignore_leading_space=1 ;;
381 n) sort_numeric=1 sort_ignore_leading_space=1 ;;
382 k) sort_field="${OPTARG%%,*}" ;; # only up to first comma
383 # NB: Unlike sort(1) only one POS allowed
384 t) sort_sep="$OPTARG"
385 if [ ${#sort_sep} -gt 1 ]; then
386 echo "$funcname: multi-character tab \`$sort_sep'" >&2
394 shift $(( $OPTIND - 1 ))
396 # Create transformation pattern to trim leading text if desired
397 case "$sort_field" in
398 ""|[!0-9]*|*[!0-9.]*)
399 echo "$funcname: invalid sort field \`$sort_field'" >&2
403 skip_leading=${sort_field#*.} sort_field=${sort_field%%.*}
404 while [ ${skip_leading:-0} -gt 1 ] 2> /dev/null; do
405 trim="$trim?" skip_leading=$(( $skip_leading - 1 ))
409 # Copy input to series of local numbered variables
410 # NB: IFS of NULL preserves leading whitespace
412 while IFS= read -r LINE || [ "$LINE" ]; do
413 nitems=$(( $nitems + 1 ))
414 local src_$nitems="$LINE"
418 # Sort numbered locals using insertion sort
420 local curitem curitem_orig curitem_mod curitem_haskey
421 local dest dest_orig dest_mod dest_haskey
424 while [ $i -le $nitems ]; do
425 curitem_haskey=1 # Assume sort field (-k POS) exists
426 eval curitem=\"\$src_$i\"
427 curitem_mod="$curitem" # for modified comparison
428 curitem_orig="$curitem" # for original comparison
430 # Trim leading whitespace if desired
431 if [ "$sort_ignore_leading_space" ]; then
432 while case "$curitem_orig" in
433 [$IFS]*) : ;; *) false; esac
435 curitem_orig="${curitem_orig#?}"
437 curitem_mod="$curitem_orig"
440 # Shift modified comparison value if sort field (-k POS) is > 1
442 while [ $n -gt 1 ]; do
443 case "$curitem_mod" in
445 # Cut text up-to (and incl.) first separator
446 curitem_mod="${curitem_mod#*[$sort_sep]}"
448 # Skip NULLs unless strict field splitting
449 [ "$sort_strict_fields" ] ||
450 [ "${curitem_mod%%[$sort_sep]*}" ] ||
455 # Asked for a field that doesn't exist
456 curitem_haskey= break
461 # Trim trailing words if sort field >= 1
462 [ $sort_field -ge 1 -a "$sort_numeric" ] &&
463 curitem_mod="${curitem_mod%%[$sort_sep]*}"
465 # Apply optional trim (-k POS.TRIM) to cut leading characters
466 curitem_mod="${curitem_mod#$trim}"
468 # Determine the type of modified comparison to use initially
469 # NB: Prefer numerical if requested but fallback to standard
470 case "$curitem_mod" in
471 ""|[!0-9]*) # NULL or begins with non-number
473 [ "$sort_numeric" ] && curitem_mod=0
476 if [ "$sort_numeric" ]; then
478 curitem_mod="${curitem_mod%%[!0-9]*}"
479 # NB: trailing non-digits removed
480 # otherwise numeric comparison fails
486 # If first time through, short-circuit below position-search
487 if [ $i -le 1 ]; then
494 # Find appropriate element position
498 dest_haskey=$curitem_haskey
499 eval dest=\"\$dest_$d\"
500 dest_mod="$dest" # for modified comparison
501 dest_orig="$dest" # for original comparison
503 # Trim leading whitespace if desired
504 if [ "$sort_ignore_leading_space" ]; then
505 while case "$dest_orig" in
506 [$IFS]*) : ;; *) false; esac
508 dest_orig="${dest_orig#?}"
510 dest_mod="$dest_orig"
513 # Shift modified value if sort field (-k POS) is > 1
515 while [ $n -gt 1 ]; do
518 # Cut text up-to (and incl.) 1st sep
519 dest_mod="${dest_mod#*[$sort_sep]}"
521 # Skip NULLs unless strict fields
522 [ "$sort_strict_fields" ] ||
523 [ "${dest_mod%%[$sort_sep]*}" ] ||
528 # Asked for a field that doesn't exist
534 # Trim trailing words if sort field >= 1
535 [ $sort_field -ge 1 -a "$sort_numeric" ] &&
536 dest_mod="${dest_mod%%[$sort_sep]*}"
538 # Apply optional trim (-k POS.TRIM), cut leading chars
539 dest_mod="${dest_mod#$trim}"
541 # Determine type of modified comparison to use
542 # NB: Prefer numerical if requested, fallback to std
544 ""|[!0-9]*) # NULL or begins with non-number
546 [ "$sort_numeric" ] && dest_mod=0
549 if [ "$sort_numeric" ]; then
551 dest_mod="${dest_mod%%[!0-9]*}"
552 # NB: kill trailing non-digits
553 # for numeric comparison safety
559 # Break if we've found the proper element position
560 if [ "$curitem_haskey" -a "$dest_haskey" ]; then
561 if [ "$dest_mod" = "$curitem_mod" ]; then
562 [ "$dest_orig" ">" "$curitem_orig" ] &&
564 elif [ "$dest_mod" $gt "$curitem_mod" ] \
570 [ "$dest_orig" ">" "$curitem_orig" ] && break
573 # Break if we've hit the end
574 [ $d -ge $i ] && break
579 # Shift remaining positions forward, making room for new item
581 while [ $n -ge $d ]; do
582 # Shift destination item forward one placement
583 eval dest_$(( $n + 1 ))=\"\$dest_$n\"
588 if [ $i -eq 1 ]; then
589 local dest_1="$curitem"
591 local dest_$d="$curitem"
597 # Print sorted results
599 while [ $d -le $nitems ]; do
600 eval echo \"\$dest_$d\"
606 # wait_for_pids pid [pid ...]
607 # spins until none of the pids exist
611 local _list _prefix _nlist _j
614 if [ -z "$_list" ]; then
621 if kill -0 $_j 2>/dev/null; then
622 _nlist="${_nlist}${_nlist:+ }$_j"
623 [ -n "$_prefix" ] && sleep 1
626 if [ -z "$_nlist" ]; then
630 echo -n ${_prefix:-"Waiting for PIDS: "}$_list
632 pwait $_list 2>/dev/null
634 if [ -n "$_prefix" ]; then
640 # get_pidfile_from_conf string file
642 # Takes a string to search for in the specified file.
643 # Ignores lines with traditional comment characters.
647 # if get_pidfile_from_conf string file; then
648 # pidfile="$_pidfile_from_conf"
650 # pidfile='appropriate default'
653 get_pidfile_from_conf()
655 if [ -z "$1" -o -z "$2" ]; then
656 err 3 "USAGE: get_pidfile_from_conf string file ($name)"
659 local string file line
661 string="$1" ; file="$2"
663 if [ ! -s "$file" ]; then
664 err 3 "get_pidfile_from_conf: $file does not exist ($name)"
669 *[#\;]*${string}*) continue ;;
670 *${string}*) break ;;
674 if [ -n "$line" ]; then
676 _pidfile_from_conf="/${line%%[\"\;]*}"
684 # If rc_quiet is set (usually as a result of using faststart at
685 # boot time) check if rc_startmsgs is enabled.
689 if [ -n "$rc_quiet" ]; then
690 checkyesno rc_startmsgs
697 # run_rc_command argument
698 # Search for argument in the list of supported commands, which is:
699 # "start stop restart rcvar status poll ${extra_commands}"
700 # If there's a match, run ${argument}_cmd or the default method
703 # If argument has a given prefix, then change the operation as follows:
706 # fast Skip the pid check, and set rc_fast=yes, rc_quiet=yes
707 # force Set ${rcvar} to YES, and set rc_force=yes
708 # one Set ${rcvar} to YES
709 # quiet Don't output some diagnostics, and set rc_quiet=yes
711 # The following globals are used:
713 # Name Needed Purpose
714 # ---- ------ -------
715 # name y Name of script.
717 # command n Full path to command.
718 # Not needed if ${rc_arg}_cmd is set for
721 # command_args n Optional args/shell directives for command.
723 # command_interpreter n If not empty, command is interpreted, so
724 # call check_{pidfile,process}() appropriately.
726 # desc n Description of script.
728 # extra_commands n List of extra commands supported.
730 # pidfile n If set, use check_pidfile $pidfile $command,
731 # otherwise use check_process $command.
732 # In either case, only check if $command is set.
734 # procname n Process name to check for instead of $command.
736 # rcvar n This is checked with checkyesno to determine
737 # if the action should be run.
739 # ${name}_program n Full path to command.
740 # Meant to be used in /etc/rc.conf to override
743 # ${name}_chroot n Directory to chroot to before running ${command}
744 # Requires /usr to be mounted.
746 # ${name}_chdir n Directory to cd to before running ${command}
747 # (if not using ${name}_chroot).
749 # ${name}_flags n Arguments to call ${command} with.
750 # NOTE: $flags from the parent environment
751 # can be used to override this.
753 # ${name}_env n Environment variables to run ${command} with.
755 # ${name}_fib n Routing table number to run ${command} with.
757 # ${name}_nice n Nice level to run ${command} at.
759 # ${name}_oomprotect n Don't kill ${command} when swap space is exhausted.
761 # ${name}_user n User to run ${command} as, using su(1) if not
762 # using ${name}_chroot.
763 # Requires /usr to be mounted.
765 # ${name}_group n Group to run chrooted ${command} as.
766 # Requires /usr to be mounted.
768 # ${name}_groups n Comma separated list of supplementary groups
769 # to run the chrooted ${command} with.
770 # Requires /usr to be mounted.
772 # ${name}_prepend n Command added before ${command}.
774 # ${name}_login_class n Login class to use, else "daemon".
776 # ${rc_arg}_cmd n If set, use this as the method when invoked;
777 # Otherwise, use default command (see below)
779 # ${rc_arg}_precmd n If set, run just before performing the
780 # ${rc_arg}_cmd method in the default
781 # operation (i.e, after checking for required
782 # bits and process (non)existence).
783 # If this completes with a non-zero exit code,
784 # don't run ${rc_arg}_cmd.
786 # ${rc_arg}_postcmd n If set, run just after performing the
787 # ${rc_arg}_cmd method, if that method
788 # returned a zero exit code.
790 # required_dirs n If set, check for the existence of the given
791 # directories before running a (re)start command.
793 # required_files n If set, check for the readability of the given
794 # files before running a (re)start command.
796 # required_modules n If set, ensure the given kernel modules are
797 # loaded before running a (re)start command.
798 # The check and possible loads are actually
799 # done after start_precmd so that the modules
800 # aren't loaded in vain, should the precmd
801 # return a non-zero status to indicate a error.
802 # If a word in the list looks like "foo:bar",
803 # "foo" is the KLD file name and "bar" is the
804 # module name. If a word looks like "foo~bar",
805 # "foo" is the KLD file name and "bar" is a
806 # egrep(1) pattern matching the module name.
807 # Otherwise the module name is assumed to be
808 # the same as the KLD file name, which is most
809 # common. See load_kld().
811 # required_vars n If set, perform checkyesno on each of the
812 # listed variables before running the default
815 # Default behaviour for a given argument, if no override method is
818 # Argument Default behaviour
819 # -------- -----------------
820 # start if !running && checkyesno ${rcvar}
824 # rc_pid=$(check_pidfile $pidfile $command)
826 # rc_pid=$(check_process $command)
827 # kill $sig_stop $rc_pid
828 # wait_for_pids $rc_pid
829 # ($sig_stop defaults to TERM.)
831 # reload Similar to stop, except use $sig_reload instead,
832 # and doesn't wait_for_pids.
833 # $sig_reload defaults to HUP.
834 # Note that `reload' isn't provided by default,
835 # it should be enabled via $extra_commands.
837 # restart Run `stop' then `start'.
839 # status Show if ${command} is running, etc.
841 # poll Wait for ${command} to exit.
843 # rcvar Display what rc.conf variable is used (if any).
845 # enabled Return true if the service is enabled.
847 # describe Show the service's description
849 # extracommands Show the service's extra commands
851 # Variables available to methods, and after run_rc_command() has
856 # rc_arg Argument to command, after fast/force/one processing
859 # rc_flags Flags to start the default command with.
860 # Defaults to ${name}_flags, unless overridden
861 # by $flags from the environment.
862 # This variable may be changed by the precmd method.
864 # rc_pid PID of command (if appropriate)
866 # rc_fast Not empty if "fast" was provided (q.v.)
868 # rc_force Not empty if "force" was provided (q.v.)
870 # rc_quiet Not empty if "quiet" was provided
877 if [ -z "$name" ]; then
878 err 3 'run_rc_command: $name is not set.'
881 # Don't repeat the first argument when passing additional command-
882 # line arguments to the command subroutines.
889 fast*) # "fast" prefix; don't check pid
890 rc_arg=${rc_arg#fast}
894 force*) # "force" prefix; always run
897 rc_arg=${rc_arg#${_rc_prefix}}
898 if [ -n "${rcvar}" ]; then
902 one*) # "one" prefix; set ${rcvar}=yes
904 rc_arg=${rc_arg#${_rc_prefix}}
905 if [ -n "${rcvar}" ]; then
909 quiet*) # "quiet" prefix; omit some messages
911 rc_arg=${rc_arg#${_rc_prefix}}
916 eval _override_command=\$${name}_program
917 command=${_override_command:-$command}
919 _keywords="start stop restart rcvar enabled describe extracommands $extra_commands"
922 _procname=${procname:-${command}}
924 # setup pid check command
925 if [ -n "$_procname" ]; then
926 if [ -n "$pidfile" ]; then
927 _pidcmd='rc_pid=$(check_pidfile '"$pidfile $_procname $command_interpreter"')'
929 _pidcmd='rc_pid=$(check_process '"$_procname $command_interpreter"')'
931 if [ -n "$_pidcmd" ]; then
932 _keywords="${_keywords} status poll"
936 if [ -z "$rc_arg" ]; then
940 if [ "$rc_arg" = "enabled" ] ; then
945 if [ -n "$flags" ]; then # allow override from environment
948 eval rc_flags=\$${name}_flags
950 eval _chdir=\$${name}_chdir _chroot=\$${name}_chroot \
951 _nice=\$${name}_nice _user=\$${name}_user \
952 _group=\$${name}_group _groups=\$${name}_groups \
953 _fib=\$${name}_fib _env=\$${name}_env \
954 _prepend=\$${name}_prepend _login_class=\${${name}_login_class:-daemon} \
955 _oomprotect=\$${name}_oomprotect
957 if [ -n "$_user" ]; then # unset $_user if running as that user
958 if [ "$_user" = "$(eval $IDCMD)" ]; then
963 [ -z "$autoboot" ] && eval $_pidcmd # determine the pid if necessary
965 for _elem in $_keywords; do
966 if [ "$_elem" != "$rc_arg" ]; then
969 # if ${rcvar} is set, $1 is not "rcvar" and not "describe"
970 # and ${rc_pid} is not set, then run
971 # checkyesno ${rcvar}
972 # and return if that failed
974 if [ -n "${rcvar}" -a "$rc_arg" != "rcvar" -a "$rc_arg" != "stop" \
975 -a "$rc_arg" != "describe" ] ||
976 [ -n "${rcvar}" -a "$rc_arg" = "stop" -a -z "${rc_pid}" ]; then
977 if ! checkyesno ${rcvar}; then
978 if [ -n "${rc_quiet}" ]; then
981 echo -n "Cannot '${rc_arg}' $name. Set ${rcvar} to "
982 echo -n "YES in /etc/rc.conf or use 'one${rc_arg}' "
983 echo "instead of '${rc_arg}'."
988 if [ $rc_arg = "start" -a -z "$rc_fast" -a -n "$rc_pid" ]; then
989 if [ -z "$rc_quiet" ]; then
990 echo 1>&2 "${name} already running? " \
996 # if there's a custom ${XXX_cmd},
997 # run that instead of the default
999 eval _cmd=\$${rc_arg}_cmd \
1000 _precmd=\$${rc_arg}_precmd \
1001 _postcmd=\$${rc_arg}_postcmd
1003 if [ -n "$_cmd" ]; then
1004 _run_rc_precmd || return 1
1005 _run_rc_doit "$_cmd $rc_extra_args" || return 1
1010 case "$rc_arg" in # default operations...
1013 if [ -n "$desc" ]; then
1019 echo "$extra_commands"
1023 _run_rc_precmd || return 1
1024 if [ -n "$rc_pid" ]; then
1025 echo "${name} is running as pid $rc_pid."
1027 echo "${name} is not running."
1034 if [ ! -x "${_chroot}${_chroot:+/}${command}" ]; then
1035 warn "run_rc_command: cannot run $command"
1039 if ! _run_rc_precmd; then
1040 warn "failed precmd routine for ${name}"
1044 # setup the full command to run
1046 check_startmsgs && echo "Starting ${name}."
1047 if [ -n "$_chroot" ]; then
1049 ${_nice:+nice -n $_nice }\
1050 ${_fib:+setfib -F $_fib }\
1051 ${_env:+env $_env }\
1052 chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
1053 $_chroot $command $rc_flags $command_args"
1056 ${_chdir:+cd $_chdir && }\
1057 ${_fib:+setfib -F $_fib }\
1058 ${_env:+env $_env }\
1059 $command $rc_flags $command_args"
1060 if [ -n "$_user" ]; then
1061 _doit="su -m $_user -c 'sh -c \"$_doit\"'"
1063 if [ -n "$_nice" ]; then
1064 if [ -z "$_user" ]; then
1065 _doit="sh -c \"$_doit\""
1067 _doit="nice -n $_nice $_doit"
1069 if [ -n "$_prepend" ]; then
1070 _doit="$_prepend $_doit"
1074 # Prepend default limits
1075 _doit="limits -C $_login_class $_doit"
1077 # run the full command
1079 if ! _run_rc_doit "$_doit"; then
1080 warn "failed to start ${name}"
1084 # finally, run postcmd
1090 if [ -z "$rc_pid" ]; then
1091 [ -n "$rc_fast" ] && return 0
1096 _run_rc_precmd || return 1
1098 # send the signal to stop
1100 echo "Stopping ${name}."
1101 _doit=$(_run_rc_killcmd "${sig_stop:-TERM}")
1102 _run_rc_doit "$_doit" || return 1
1104 # wait for the command to exit,
1106 wait_for_pids $rc_pid
1112 if [ -z "$rc_pid" ]; then
1117 _run_rc_precmd || return 1
1119 _doit=$(_run_rc_killcmd "${sig_reload:-HUP}")
1120 _run_rc_doit "$_doit" || return 1
1126 # prevent restart being called more
1127 # than once by any given script
1129 if ${_rc_restart_done:-false}; then
1132 _rc_restart_done=true
1134 _run_rc_precmd || return 1
1136 # run those in a subshell to keep global variables
1137 ( run_rc_command ${_rc_prefix}stop $rc_extra_args )
1138 ( run_rc_command ${_rc_prefix}start $rc_extra_args )
1140 [ $_return -ne 0 ] && [ -z "$rc_force" ] && return 1
1146 _run_rc_precmd || return 1
1147 if [ -n "$rc_pid" ]; then
1148 wait_for_pids $rc_pid
1155 if [ -n "$desc" ]; then
1161 # Get unique vars in $rcvar $rcvars
1162 for _v in $rcvar $rcvars; do
1164 $_v\ *|\ *$_v|*\ $_v\ *) ;;
1165 *) v="${v# } $_v" ;;
1169 # Display variables.
1171 if [ -z "$_v" ]; then
1175 eval _desc=\$${_v}_desc
1176 eval _defval=\$${_v}_defval
1179 eval echo \"$_v=\\\"\$$_v\\\"\"
1180 # decode multiple lines of _desc
1181 while [ -n "$_desc" ]; do
1184 echo "# $_h ${_desc%%^^*}"
1189 echo "# $_h ${_desc}"
1194 echo "# (default: \"$_defval\")"
1205 # Apply protect(1) to the PID if ${name}_oomprotect is set.
1208 if [ -n "$_oomprotect" ]; then
1209 if [ -f "${PROTECT}" ]; then
1210 pid=$(check_process $command)
1211 case $_oomprotect in
1213 ${PROTECT} -i -p ${pid}
1216 ${PROTECT} -p ${pid}
1227 echo 1>&2 "$0: unknown directive '$rc_arg'."
1233 # Helper functions for run_rc_command: common code.
1234 # They use such global variables besides the exported rc_* ones:
1237 # ------------------
1244 check_required_before "$rc_arg" || return 1
1246 if [ -n "$_precmd" ]; then
1247 debug "run_rc_command: ${rc_arg}_precmd: $_precmd $rc_extra_args"
1248 eval "$_precmd $rc_extra_args"
1251 # If precmd failed and force isn't set, request exit.
1252 if [ $_return -ne 0 ] && [ -z "$rc_force" ]; then
1257 check_required_after "$rc_arg" || return 1
1264 if [ -n "$_postcmd" ]; then
1265 debug "run_rc_command: ${rc_arg}_postcmd: $_postcmd $rc_extra_args"
1266 eval "$_postcmd $rc_extra_args"
1274 debug "run_rc_command: doit: $*"
1278 # If command failed and force isn't set, request exit.
1279 if [ $_return -ne 0 ] && [ -z "$rc_force" ]; then
1286 _run_rc_notrunning()
1290 if [ -n "$pidfile" ]; then
1291 _pidmsg=" (check $pidfile)."
1295 echo 1>&2 "${name} not running?${_pidmsg}"
1302 _cmd="kill -$1 $rc_pid"
1303 if [ -n "$_user" ]; then
1304 _cmd="su -m ${_user} -c 'sh -c \"${_cmd}\"'"
1310 # run_rc_script file arg
1311 # Start the script `file' with `arg', and correctly handle the
1312 # return value from the script.
1313 # If `file' ends with `.sh' and lives in /etc/rc.d, ignore it as it's
1314 # an old-style startup file.
1315 # If `file' ends with `.sh' and does not live in /etc/rc.d, it's sourced
1316 # into the current environment if $rc_fast_and_loose is set; otherwise
1317 # it is run as a child process.
1318 # If `file' appears to be a backup or scratch file, ignore it.
1319 # Otherwise if it is executable run as a child process.
1325 if [ -z "$_file" -o -z "$_arg" ]; then
1326 err 3 'USAGE: run_rc_script file arg'
1329 unset name command command_args command_interpreter \
1330 extra_commands pidfile procname \
1331 rcvar rcvars rcvars_obsolete required_dirs required_files \
1333 eval unset ${_arg}_cmd ${_arg}_precmd ${_arg}_postcmd
1336 /etc/rc.d/*.sh) # no longer allowed in the base
1337 warn "Ignoring old-style startup script $_file"
1339 *[~#]|*.OLD|*.bak|*.orig|*,v) # scratch file; skip
1340 warn "Ignoring scratch file $_file"
1342 *) # run in subshell
1343 if [ -x $_file ]; then
1344 if [ -n "$rc_fast_and_loose" ]; then
1347 ( trap "echo Script $_file interrupted >&2 ; kill -QUIT $$" 3
1348 trap "echo Script $_file interrupted >&2 ; exit 1" 2
1349 trap "echo Script $_file running >&2" 29
1350 set $_arg; . $_file )
1358 # load_rc_config [service]
1359 # Source in the configuration file(s) for a given service.
1360 # If no service is specified, only the global configuration
1361 # file(s) will be loaded.
1365 local _name _rcvar_val _var _defval _v _msg _new _d
1368 if ${_rc_conf_loaded:-false}; then
1371 if [ -r /etc/defaults/rc.conf ]; then
1372 debug "Sourcing /etc/defaults/rc.conf"
1373 . /etc/defaults/rc.conf
1375 elif [ -r /etc/rc.conf ]; then
1376 debug "Sourcing /etc/rc.conf (/etc/defaults/rc.conf doesn't exist)."
1379 _rc_conf_loaded=true
1382 # If a service name was specified, attempt to load
1383 # service-specific configuration
1384 if [ -n "$_name" ] ; then
1385 for _d in /etc ${local_startup}; do
1387 if [ -f ${_d}/rc.conf.d/"$_name" ]; then
1388 debug "Sourcing ${_d}/rc.conf.d/$_name"
1389 . ${_d}/rc.conf.d/"$_name"
1390 elif [ -d ${_d}/rc.conf.d/"$_name" ] ; then
1392 for _rc in ${_d}/rc.conf.d/"$_name"/* ; do
1393 if [ -f "$_rc" ] ; then
1394 debug "Sourcing $_rc"
1402 # Set defaults if defined.
1403 for _var in $rcvar $rcvars; do
1404 eval _defval=\$${_var}_defval
1405 if [ -n "$_defval" ]; then
1406 eval : \${$_var:=\$${_var}_defval}
1410 # check obsolete rc.conf variables
1411 for _var in $rcvars_obsolete; do
1413 eval _msg=\$${_var}_obsolete_msg
1414 eval _new=\$${_var}_newvar
1419 if [ -z "$_new" ]; then
1422 eval $_new=\"\$$_var\"
1423 if [ -z "$_msg" ]; then
1424 _msg="Use \$$_new instead."
1427 warn "\$$_var is obsolete. $_msg"
1434 # load_rc_config_var name var
1435 # Read the rc.conf(5) var for name and set in the
1436 # current shell, using load_rc_config in a subshell to prevent
1437 # unwanted side effects from other variable assignments.
1439 load_rc_config_var()
1441 if [ $# -ne 2 ]; then
1442 err 3 'USAGE: load_rc_config_var name var'
1445 load_rc_config '$1' >/dev/null;
1446 if [ -n "${'$2'}" -o "${'$2'-UNSET}" != "UNSET" ]; then
1447 echo '$2'=\'\''${'$2'}\'\'';
1454 # Print a usage string for $0, with `commands' being a list of
1459 echo -n 1>&2 "Usage: $0 [fast|force|one|quiet]("
1463 echo -n 1>&2 "$_sep$_elem"
1471 # err exitval message
1472 # Display message to stderr and log to the syslog, and exit with exitval.
1479 if [ -x /usr/bin/logger ]; then
1480 logger "$0: ERROR: $*"
1482 echo 1>&2 "$0: ERROR: $*"
1488 # Display message to stderr and log to the syslog.
1492 if [ -x /usr/bin/logger ]; then
1493 logger "$0: WARNING: $*"
1495 echo 1>&2 "$0: WARNING: $*"
1500 # Display informational message to stdout and log to syslog.
1505 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
1506 if [ -x /usr/bin/logger ]; then
1507 logger "$0: INFO: $*"
1516 # If debugging is enabled in rc.conf output message to stderr.
1517 # BEWARE that you don't call any subroutine that itself calls this
1523 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
1524 if [ -x /usr/bin/logger ]; then
1525 logger "$0: DEBUG: $*"
1527 echo 1>&2 "$0: DEBUG: $*"
1533 # backup_file action file cur backup
1534 # Make a backup copy of `file' into `cur', and save the previous
1535 # version of `cur' as `backup' or use rcs for archiving.
1537 # This routine checks the value of the backup_uses_rcs variable,
1538 # which can be either YES or NO.
1540 # The `action' keyword can be one of the following:
1542 # add `file' is now being backed up (and is possibly
1543 # being reentered into the backups system). `cur'
1544 # is created and RCS files, if necessary, are
1547 # update `file' has changed and needs to be backed up.
1548 # If `cur' exists, it is copied to to `back' or
1549 # checked into RCS (if the repository file is old),
1550 # and then `file' is copied to `cur'. Another RCS
1551 # check in done here if RCS is being used.
1553 # remove `file' is no longer being tracked by the backups
1554 # system. If RCS is not being used, `cur' is moved
1555 # to `back', otherwise an empty file is checked in,
1556 # and then `cur' is removed.
1566 if checkyesno backup_uses_rcs; then
1567 _msg0="backup archive"
1570 # ensure that history file is not locked
1571 if [ -f $_cur,v ]; then
1572 rcs -q -u -U -M $_cur
1575 # ensure after switching to rcs that the
1576 # current backup is not lost
1577 if [ -f $_cur ]; then
1578 # no archive, or current newer than archive
1579 if [ ! -f $_cur,v -o $_cur -nt $_cur,v ]; then
1580 ci -q -f -u -t-"$_msg0" -m"$_msg1" $_cur
1589 ci -q -f -u -t-"$_msg0" -m"$_msg1" $_cur
1592 chown root:wheel $_cur $_cur,v
1596 ci -q -f -u -t-"$_msg0" -m"$_msg1" $_cur
1598 chown root:wheel $_cur $_cur,v
1605 if [ -f $_cur ]; then
1609 chown root:wheel $_cur
1618 # make_symlink src link
1619 # Make a symbolic link 'link' to src from basedir. If the
1620 # directory in which link is to be created does not exist
1621 # a warning will be displayed and an error will be returned.
1622 # Returns 0 on success, 1 otherwise.
1626 local src link linkdir _me
1629 linkdir="`dirname $link`"
1630 _me="make_symlink()"
1632 if [ -z "$src" -o -z "$link" ]; then
1633 warn "$_me: requires two arguments."
1636 if [ ! -d "$linkdir" ]; then
1637 warn "$_me: the directory $linkdir does not exist."
1640 if ! ln -sf $src $link; then
1641 warn "$_me: unable to make a symbolic link from $link to $src"
1647 # devfs_rulesets_from_file file
1648 # Reads a set of devfs commands from file, and creates
1649 # the specified rulesets with their rules. Returns non-zero
1650 # if there was an error.
1652 devfs_rulesets_from_file()
1654 local file _err _me _opts
1656 _me="devfs_rulesets_from_file"
1659 if [ -z "$file" ]; then
1660 warn "$_me: you must specify a file"
1663 if [ ! -e "$file" ]; then
1664 debug "$_me: no such file ($file)"
1668 # Disable globbing so that the rule patterns are not expanded
1669 # by accident with matching filesystem entries.
1672 debug "reading rulesets from file ($file)"
1680 rulenum=`expr "$line" : "\[.*=\([0-9]*\)\]"`
1681 if [ -z "$rulenum" ]; then
1682 warn "$_me: cannot extract rule number ($line)"
1686 rulename=`expr "$line" : "\[\(.*\)=[0-9]*\]"`
1687 if [ -z "$rulename" ]; then
1688 warn "$_me: cannot extract rule name ($line)"
1692 eval $rulename=\$rulenum
1693 debug "found ruleset: $rulename=$rulenum"
1694 if ! /sbin/devfs rule -s $rulenum delset; then
1700 rulecmd="${line%%"\#*"}"
1701 # evaluate the command incase it includes
1703 if [ -n "$rulecmd" ]; then
1704 debug "adding rule ($rulecmd)"
1705 if ! eval /sbin/devfs rule -s $rulenum $rulecmd
1713 if [ $_err -ne 0 ]; then
1714 debug "error in $_me"
1718 case $_opts in *f*) ;; *) set +f ;; esac
1722 # devfs_init_rulesets
1723 # Initializes rulesets from configuration files. Returns
1724 # non-zero if there was an error.
1726 devfs_init_rulesets()
1729 _me="devfs_init_rulesets"
1731 # Go through this only once
1732 if [ -n "$devfs_rulesets_init" ]; then
1733 debug "$_me: devfs rulesets already initialized"
1736 for file in $devfs_rulesets; do
1737 if ! devfs_rulesets_from_file $file; then
1738 warn "$_me: could not read rules from $file"
1742 devfs_rulesets_init=1
1743 debug "$_me: devfs rulesets initialized"
1747 # devfs_set_ruleset ruleset [dir]
1748 # Sets the default ruleset of dir to ruleset. The ruleset argument
1749 # must be a ruleset name as specified in devfs.rules(5) file.
1750 # Returns non-zero if it could not set it successfully.
1755 [ -n "$1" ] && eval rs=\$$1 || rs=
1756 [ -n "$2" ] && devdir="-m "$2"" || devdir=
1757 _me="devfs_set_ruleset"
1759 if [ -z "$rs" ]; then
1760 warn "$_me: you must specify a ruleset number"
1763 debug "$_me: setting ruleset ($rs) on mount-point (${devdir#-m })"
1764 if ! /sbin/devfs $devdir ruleset $rs; then
1765 warn "$_me: unable to set ruleset $rs to ${devdir#-m }"
1771 # devfs_apply_ruleset ruleset [dir]
1772 # Apply ruleset number $ruleset to the devfs mountpoint $dir.
1773 # The ruleset argument must be a ruleset name as specified
1774 # in a devfs.rules(5) file. Returns 0 on success or non-zero
1775 # if it could not apply the ruleset.
1777 devfs_apply_ruleset()
1780 [ -n "$1" ] && eval rs=\$$1 || rs=
1781 [ -n "$2" ] && devdir="-m "$2"" || devdir=
1782 _me="devfs_apply_ruleset"
1784 if [ -z "$rs" ]; then
1785 warn "$_me: you must specify a ruleset"
1788 debug "$_me: applying ruleset ($rs) to mount-point (${devdir#-m })"
1789 if ! /sbin/devfs $devdir rule -s $rs applyset; then
1790 warn "$_me: unable to apply ruleset $rs to ${devdir#-m }"
1796 # devfs_domount dir [ruleset]
1797 # Mount devfs on dir. If ruleset is specified it is set
1798 # on the mount-point. It must also be a ruleset name as specified
1799 # in a devfs.rules(5) file. Returns 0 on success.
1805 [ -n "$2" ] && rs=$2 || rs=
1806 _me="devfs_domount()"
1808 if [ -z "$devdir" ]; then
1809 warn "$_me: you must specify a mount-point"
1812 debug "$_me: mount-point is ($devdir), ruleset is ($rs)"
1813 if ! mount -t devfs dev "$devdir"; then
1814 warn "$_me: Unable to mount devfs on $devdir"
1817 if [ -n "$rs" ]; then
1819 devfs_set_ruleset $rs $devdir
1820 devfs -m $devdir rule applyset
1825 # Provide a function for normalizing the mounting of memory
1826 # filesystems. This should allow the rest of the code here to remain
1827 # as close as possible between 5-current and 4-stable.
1830 # $3 = (optional) extra mdmfs flags
1833 if [ -n "$3" ]; then
1836 /sbin/mdmfs $flags -s $1 md $2
1839 # Code common to scripts that need to load a kernel module
1840 # if it isn't in the kernel yet. Syntax:
1841 # load_kld [-e regex] [-m module] file
1842 # where -e or -m chooses the way to check if the module
1843 # is already loaded:
1844 # regex is egrep'd in the output from `kldstat -v',
1845 # module is passed to `kldstat -m'.
1846 # The default way is as though `-m file' were specified.
1849 local _loaded _mod _opt _re
1851 while getopts "e:m:" _opt; do
1854 m) _mod="$OPTARG" ;;
1855 *) err 3 'USAGE: load_kld [-e regex] [-m module] file' ;;
1858 shift $(($OPTIND - 1))
1859 if [ $# -ne 1 ]; then
1860 err 3 'USAGE: load_kld [-e regex] [-m module] file'
1864 if [ -n "$_re" ]; then
1865 if kldstat -v | egrep -q -e "$_re"; then
1869 if kldstat -q -m "$_mod"; then
1874 if ! kldload "$1"; then
1875 warn "Unable to load kernel module $1"
1878 info "$1 kernel module loaded."
1881 debug "load_kld: $1 kernel module already loaded."
1886 # ltr str src dst [var]
1887 # Change every $src in $str to $dst.
1888 # Useful when /usr is not yet mounted and we cannot use tr(1), sed(1) nor
1889 # awk(1). If var is non-NULL, set it to the result.
1892 local _str _src _dst _out _com _var
1900 for _com in ${_str}; do
1901 if [ -z "${_out}" ]; then
1904 _out="${_out}${_dst}${_com}"
1907 if [ -n "${_var}" ]; then
1908 setvar "${_var}" "${_out}"
1914 # Creates a list of providers for GELI encryption.
1917 local devices devices2
1918 local provider mountpoint type options rest
1920 # Create list of GELI providers from fstab.
1921 while read provider mountpoint type options rest ; do
1922 case ":${options}" in
1931 case ":${provider}" in
1936 # Skip swap devices.
1937 if [ "${type}" = "swap" -o "${options}" = "sw" -o "${noauto}" = "yes" ]; then
1940 devices="${devices} ${provider}"
1945 # Append providers from geli_devices.
1946 devices="${devices} ${geli_devices}"
1948 for provider in ${devices}; do
1949 provider=${provider%.eli}
1950 provider=${provider#/dev/}
1951 devices2="${devices2} ${provider}"
1957 # Originally, root mount hold had to be released before mounting
1958 # the root filesystem. This delayed the boot, so it was changed
1959 # to only wait if the root device isn't readily available. This
1960 # can result in rc scripts executing before all the devices - such
1961 # as graid(8), or USB disks - can be accessed. This function can
1962 # be used to explicitly wait for root mount holds to be released.
1965 local wait waited holders
1969 holders="$(sysctl -n vfs.root_mount_hold)"
1970 if [ -z "${holders}" ]; then
1973 if [ ${waited} -eq 0 ]; then
1974 echo -n "Waiting ${root_hold_delay}s" \
1975 "for the root mount holders: ${holders}"
1979 if [ ${waited} -ge ${root_hold_delay} ]; then
1984 waited=$(($waited + 1))
1988 # Find scripts in local_startup directories that use the old syntax
1990 find_local_scripts_old() {
1993 for dir in ${local_startup}; do
1994 if [ -d "${dir}" ]; then
1995 for file in ${dir}/[0-9]*.sh; do
1996 grep '^# PROVIDE:' $file >/dev/null 2>&1 &&
1998 zlist="$zlist $file"
2000 for file in ${dir}/[!0-9]*.sh; do
2001 grep '^# PROVIDE:' $file >/dev/null 2>&1 &&
2003 slist="$slist $file"
2009 find_local_scripts_new() {
2011 for dir in ${local_startup}; do
2012 if [ -d "${dir}" ]; then
2013 for file in `grep -l '^# PROVIDE:' ${dir}/* 2>/dev/null`; do
2016 *) if [ -x "$file" ]; then
2017 local_rc="${local_rc} ${file}"
2026 # check_required_{before|after} command
2027 # Check for things required by the command before and after its precmd,
2028 # respectively. The two separate functions are needed because some
2029 # conditions should prevent precmd from being run while other things
2030 # depend on precmd having already been run.
2032 check_required_before()
2038 for _f in $required_vars; do
2039 if ! checkyesno $_f; then
2040 warn "\$${_f} is not enabled."
2041 if [ -z "$rc_force" ]; then
2047 for _f in $required_dirs; do
2048 if [ ! -d "${_f}/." ]; then
2049 warn "${_f} is not a directory."
2050 if [ -z "$rc_force" ]; then
2056 for _f in $required_files; do
2057 if [ ! -r "${_f}" ]; then
2058 warn "${_f} is not readable."
2059 if [ -z "$rc_force" ]; then
2070 check_required_after()
2076 for _f in $required_modules; do
2078 *~*) _args="-e ${_f#*~} ${_f%%~*}" ;;
2079 *:*) _args="-m ${_f#*:} ${_f%%:*}" ;;
2082 if ! load_kld ${_args}; then
2083 if [ -z "$rc_force" ]; then
2095 # Return true if security.jail.$mib exists and set to 1.
2102 if _v=$(${SYSCTL_N} "security.jail.$_mib" 2> /dev/null); then
2110 # check_kern_features mib
2111 # Return existence of kern.features.* sysctl MIB as true or
2112 # false. The result will be cached in $_rc_cache_kern_features_
2113 # namespace. "0" means the kern.features.X exists.
2115 check_kern_features()
2119 [ -n "$1" ] || return 1;
2120 eval _v=\$_rc_cache_kern_features_$1
2121 [ -n "$_v" ] && return "$_v";
2123 if ${SYSCTL_N} kern.features.$1 > /dev/null 2>&1; then
2124 eval _rc_cache_kern_features_$1=0
2127 eval _rc_cache_kern_features_$1=1
2132 # check_namevarlist var
2133 # Return "0" if ${name}_var is reserved in rc.subr.
2135 _rc_namevarlist="program chroot chdir env flags fib nice user group groups prepend"
2140 for _v in $_rc_namevarlist; do
2149 # _echoonce var msg mode
2150 # mode=0: Echo $msg if ${$var} is empty.
2151 # After doing echo, a string is set to ${$var}.
2153 # mode=1: Echo $msg if ${$var} is a string with non-zero length.
2157 local _var _msg _mode
2163 1) [ -n "$_var" ] && echo "$_msg" ;;
2164 *) [ -z "$_var" ] && echo -n "$_msg" && eval "$1=finished" ;;
2168 fi # [ -z "${_rc_subr_loaded}" ]