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 [ -n "${_rc_subr_loaded}" ]; then
48 SYSCTL_N="${SYSCTL} -n"
50 PROTECT="/usr/bin/protect"
52 IDCMD="if [ -x $ID ]; then $ID -un; fi"
61 # List vars matching pattern.
65 set | { while read LINE; do
68 "$LINE"|*[!a-zA-Z0-9_]*) continue ;;
74 # set_rcvar [var] [defval] [desc]
76 # Echo or define a rc.conf(5) variable name. Global variable
79 # If no argument is specified, echo "${name}_enable".
81 # If only a var is specified, echo "${var}_enable".
83 # If var and defval are specified, the ${var} is defined as
84 # rc.conf(5) variable and the default value is ${defvar}. An
85 # optional argument $desc can also be specified to add a
86 # description for that.
93 0) echo ${name}_enable ;;
94 1) echo ${1}_enable ;;
96 debug "set_rcvar: \$$1=$2 is added" \
97 " as a rc.conf(5) variable."
99 rcvars="${rcvars# } $_var"
100 eval ${_var}_defval=\"$2\"
102 eval ${_var}_desc=\"$*\"
107 # set_rcvar_obsolete oldvar [newvar] [msg]
108 # Define obsolete variable.
109 # Global variable $rcvars_obsolete is used.
115 debug "set_rcvar_obsolete: \$$1(old) -> \$$2(new) is defined"
117 rcvars_obsolete="${rcvars_obsolete# } $1"
118 eval ${1}_newvar=\"$2\"
120 eval ${_var}_obsolete_msg=\"$*\"
124 # force_depend script [rcvar]
125 # Force a service to start. Intended for use by services
126 # to resolve dependency issues.
127 # $1 - filename of script, in /etc/rc.d, to run
128 # $2 - name of the script's rcvar (minus the _enable)
132 local _depend _dep_rcvar
135 _dep_rcvar="${2:-$1}_enable"
137 [ -n "$rc_fast" ] && ! checkyesno always_force_depends &&
138 checkyesno $_dep_rcvar && return 0
140 /etc/rc.d/${_depend} forcestatus >/dev/null 2>&1 && return 0
142 info "${name} depends on ${_depend}, which will be forced to start."
143 if ! /etc/rc.d/${_depend} forcestart; then
144 warn "Unable to force ${_depend}. It may already be running."
151 # Test $1 variable, and warn if not set to YES or NO.
152 # Return 0 if it's "yes" (et al), nonzero otherwise.
157 debug "checkyesno: $1 is set to $_value."
160 # "yes", "true", "on", or "1"
161 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
165 # "no", "false", "off", or "0"
166 [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
170 warn "\$${1} is not set properly - see rc.conf(5)."
178 # print the list in reverse order
184 _revlist="$_revfile $_revlist"
190 # If booting directly to multiuser or $always is enabled,
191 # send SIGTERM to the parent (/etc/rc) to abort the boot.
192 # Otherwise just exit.
199 # "yes", "true", "on", or "1"
200 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
207 if [ "$autoboot" = yes -o "$always" = true ]; then
208 echo "ERROR: ABORTING BOOT (sending SIGTERM to parent)!"
215 # mount_critical_filesystems type
216 # Go through the list of critical filesystems as provided in
217 # the rc.conf(5) variable $critical_filesystems_${type}, checking
218 # each one to see if it is mounted, and if it is not, mounting it.
220 mount_critical_filesystems()
222 eval _fslist=\$critical_filesystems_${1}
223 for _fs in $_fslist; do
226 while read what _on on _type type; do
227 if [ $on = $_fs ]; then
234 mount $_fs >/dev/null 2>&1
241 # check_pidfile pidfile procname [interpreter]
242 # Parses the first line of pidfile for a PID, and ensures
243 # that the process is running and matches procname.
244 # Prints the matching PID upon success, nothing otherwise.
245 # interpreter is optional; see _find_processes() for details.
252 if [ -z "$_pidfile" -o -z "$_procname" ]; then
253 err 3 'USAGE: check_pidfile pidfile procname [interpreter]'
255 if [ ! -f $_pidfile ]; then
256 debug "pid file ($_pidfile): not readable."
259 read _pid _junk < $_pidfile
260 if [ -z "$_pid" ]; then
261 debug "pid file ($_pidfile): no pid in file."
264 _find_processes $_procname ${_interpreter:-.} '-p '"$_pid"
268 # check_process procname [interpreter]
269 # Ensures that a process (or processes) named procname is running.
270 # Prints a list of matching PIDs.
271 # interpreter is optional; see _find_processes() for details.
277 if [ -z "$_procname" ]; then
278 err 3 'USAGE: check_process procname [interpreter]'
280 _find_processes $_procname ${_interpreter:-.} '-ax'
284 # _find_processes procname interpreter psargs
285 # Search for procname in the output of ps generated by psargs.
286 # Prints the PIDs of any matching processes, space separated.
288 # If interpreter == ".", check the following variations of procname
289 # against the first word of each command:
291 # `basename procname`
292 # `basename procname` + ":"
293 # "(" + `basename procname` + ")"
294 # "[" + `basename procname` + "]"
296 # If interpreter != ".", read the first line of procname, remove the
297 # leading #!, normalise whitespace, append procname, and attempt to
298 # match that against each command, either as is, or with extra words
299 # at the end. As an alternative, to deal with interpreted daemons
300 # using perl, the basename of the interpreter plus a colon is also
301 # tried as the prefix to procname.
305 if [ $# -ne 3 ]; then
306 err 3 'USAGE: _find_processes procname interpreter psargs'
313 if [ $_interpreter != "." ]; then # an interpreted script
314 _script="${_chroot}${_chroot:+/}$_procname"
315 if [ -r "$_script" ]; then
316 read _interp < $_script # read interpreter name
319 _interp=${_interp#\#!} # strip #!
323 shift # drop env to get real name
326 if [ $_interpreter != $1 ]; then
327 warn "\$command_interpreter $_interpreter != $1"
331 warn "no shebang line in $_script"
336 warn "cannot read shebang line from $_script"
339 _interp="$* $_procname" # cleanup spaces, add _procname
342 _fp_match='case "$_argv" in
343 ${_interp}|"${_interp} "*|"[${_interpbn}]"|"${_interpbn}: ${_procname}"*)'
344 else # a normal daemon
345 _procnamebn=${_procname##*/}
346 _fp_args='_arg0 _argv'
347 _fp_match='case "$_arg0" in
348 $_procname|$_procnamebn|${_procnamebn}:|"(${_procnamebn})"|"[${_procnamebn}]")'
352 $PS 2>/dev/null -o pid= -o jid= -o command= $_psargs"' |
353 while read _npid _jid '"$_fp_args"'; do
355 if [ "$JID" -eq "$_jid" ];
356 then echo -n "$_pref$_npid";
363 # debug "in _find_processes: proccheck is ($_proccheck)."
367 # sort_lite [-b] [-n] [-k POS] [-t SEP]
368 # A lite version of sort(1) (supporting a few options) that can be used
369 # before the real sort(1) is available (e.g., in scripts that run prior
370 # to mountcritremote). Requires only shell built-in functionality.
374 local funcname=sort_lite
375 local sort_sep="$IFS" sort_ignore_leading_space=
376 local sort_field=0 sort_strict_fields= sort_numeric=
377 local nitems=0 skip_leading=0 trim=
380 while getopts bnk:t: flag; do
382 b) sort_ignore_leading_space=1 ;;
383 n) sort_numeric=1 sort_ignore_leading_space=1 ;;
384 k) sort_field="${OPTARG%%,*}" ;; # only up to first comma
385 # NB: Unlike sort(1) only one POS allowed
386 t) sort_sep="$OPTARG"
387 if [ ${#sort_sep} -gt 1 ]; then
388 echo "$funcname: multi-character tab \`$sort_sep'" >&2
396 shift $(( $OPTIND - 1 ))
398 # Create transformation pattern to trim leading text if desired
399 case "$sort_field" in
400 ""|[!0-9]*|*[!0-9.]*)
401 echo "$funcname: invalid sort field \`$sort_field'" >&2
405 skip_leading=${sort_field#*.} sort_field=${sort_field%%.*}
406 while [ ${skip_leading:-0} -gt 1 ] 2> /dev/null; do
407 trim="$trim?" skip_leading=$(( $skip_leading - 1 ))
411 # Copy input to series of local numbered variables
412 # NB: IFS of NULL preserves leading whitespace
414 while IFS= read -r LINE || [ "$LINE" ]; do
415 nitems=$(( $nitems + 1 ))
416 local src_$nitems="$LINE"
420 # Sort numbered locals using insertion sort
422 local curitem curitem_orig curitem_mod curitem_haskey
423 local dest dest_orig dest_mod dest_haskey
426 while [ $i -le $nitems ]; do
427 curitem_haskey=1 # Assume sort field (-k POS) exists
428 eval curitem=\"\$src_$i\"
429 curitem_mod="$curitem" # for modified comparison
430 curitem_orig="$curitem" # for original comparison
432 # Trim leading whitespace if desired
433 if [ "$sort_ignore_leading_space" ]; then
434 while case "$curitem_orig" in
435 [$IFS]*) : ;; *) false; esac
437 curitem_orig="${curitem_orig#?}"
439 curitem_mod="$curitem_orig"
442 # Shift modified comparison value if sort field (-k POS) is > 1
444 while [ $n -gt 1 ]; do
445 case "$curitem_mod" in
447 # Cut text up-to (and incl.) first separator
448 curitem_mod="${curitem_mod#*[$sort_sep]}"
450 # Skip NULLs unless strict field splitting
451 [ "$sort_strict_fields" ] ||
452 [ "${curitem_mod%%[$sort_sep]*}" ] ||
457 # Asked for a field that doesn't exist
458 curitem_haskey= break
463 # Trim trailing words if sort field >= 1
464 [ $sort_field -ge 1 -a "$sort_numeric" ] &&
465 curitem_mod="${curitem_mod%%[$sort_sep]*}"
467 # Apply optional trim (-k POS.TRIM) to cut leading characters
468 curitem_mod="${curitem_mod#$trim}"
470 # Determine the type of modified comparison to use initially
471 # NB: Prefer numerical if requested but fallback to standard
472 case "$curitem_mod" in
473 ""|[!0-9]*) # NULL or begins with non-number
475 [ "$sort_numeric" ] && curitem_mod=0
478 if [ "$sort_numeric" ]; then
480 curitem_mod="${curitem_mod%%[!0-9]*}"
481 # NB: trailing non-digits removed
482 # otherwise numeric comparison fails
488 # If first time through, short-circuit below position-search
489 if [ $i -le 1 ]; then
496 # Find appropriate element position
500 dest_haskey=$curitem_haskey
501 eval dest=\"\$dest_$d\"
502 dest_mod="$dest" # for modified comparison
503 dest_orig="$dest" # for original comparison
505 # Trim leading whitespace if desired
506 if [ "$sort_ignore_leading_space" ]; then
507 while case "$dest_orig" in
508 [$IFS]*) : ;; *) false; esac
510 dest_orig="${dest_orig#?}"
512 dest_mod="$dest_orig"
515 # Shift modified value if sort field (-k POS) is > 1
517 while [ $n -gt 1 ]; do
520 # Cut text up-to (and incl.) 1st sep
521 dest_mod="${dest_mod#*[$sort_sep]}"
523 # Skip NULLs unless strict fields
524 [ "$sort_strict_fields" ] ||
525 [ "${dest_mod%%[$sort_sep]*}" ] ||
530 # Asked for a field that doesn't exist
536 # Trim trailing words if sort field >= 1
537 [ $sort_field -ge 1 -a "$sort_numeric" ] &&
538 dest_mod="${dest_mod%%[$sort_sep]*}"
540 # Apply optional trim (-k POS.TRIM), cut leading chars
541 dest_mod="${dest_mod#$trim}"
543 # Determine type of modified comparison to use
544 # NB: Prefer numerical if requested, fallback to std
546 ""|[!0-9]*) # NULL or begins with non-number
548 [ "$sort_numeric" ] && dest_mod=0
551 if [ "$sort_numeric" ]; then
553 dest_mod="${dest_mod%%[!0-9]*}"
554 # NB: kill trailing non-digits
555 # for numeric comparison safety
561 # Break if we've found the proper element position
562 if [ "$curitem_haskey" -a "$dest_haskey" ]; then
563 if [ "$dest_mod" = "$curitem_mod" ]; then
564 [ "$dest_orig" ">" "$curitem_orig" ] &&
566 elif [ "$dest_mod" $gt "$curitem_mod" ] \
572 [ "$dest_orig" ">" "$curitem_orig" ] && break
575 # Break if we've hit the end
576 [ $d -ge $i ] && break
581 # Shift remaining positions forward, making room for new item
583 while [ $n -ge $d ]; do
584 # Shift destination item forward one placement
585 eval dest_$(( $n + 1 ))=\"\$dest_$n\"
590 if [ $i -eq 1 ]; then
591 local dest_1="$curitem"
593 local dest_$d="$curitem"
599 # Print sorted results
601 while [ $d -le $nitems ]; do
602 eval echo \"\$dest_$d\"
608 # wait_for_pids pid [pid ...]
609 # spins until none of the pids exist
613 local _list _prefix _nlist _j
616 if [ -z "$_list" ]; then
623 if kill -0 $_j 2>/dev/null; then
624 _nlist="${_nlist}${_nlist:+ }$_j"
625 [ -n "$_prefix" ] && sleep 1
628 if [ -z "$_nlist" ]; then
632 echo -n ${_prefix:-"Waiting for PIDS: "}$_list
634 pwait $_list 2>/dev/null
636 if [ -n "$_prefix" ]; then
642 # get_pidfile_from_conf string file
644 # Takes a string to search for in the specified file.
645 # Ignores lines with traditional comment characters.
649 # if get_pidfile_from_conf string file; then
650 # pidfile="$_pidfile_from_conf"
652 # pidfile='appropriate default'
655 get_pidfile_from_conf()
657 if [ -z "$1" -o -z "$2" ]; then
658 err 3 "USAGE: get_pidfile_from_conf string file ($name)"
661 local string file line
663 string="$1" ; file="$2"
665 if [ ! -s "$file" ]; then
666 err 3 "get_pidfile_from_conf: $file does not exist ($name)"
671 *[#\;]*${string}*) continue ;;
672 *${string}*) break ;;
676 if [ -n "$line" ]; then
678 _pidfile_from_conf="/${line%%[\"\;]*}"
686 # If rc_quiet is set (usually as a result of using faststart at
687 # boot time) check if rc_startmsgs is enabled.
691 if [ -n "$rc_quiet" ]; then
692 checkyesno rc_startmsgs
699 # run_rc_command argument
700 # Search for argument in the list of supported commands, which is:
701 # "start stop restart rcvar status poll ${extra_commands}"
702 # If there's a match, run ${argument}_cmd or the default method
705 # If argument has a given prefix, then change the operation as follows:
708 # fast Skip the pid check, and set rc_fast=yes, rc_quiet=yes
709 # force Set ${rcvar} to YES, and set rc_force=yes
710 # one Set ${rcvar} to YES
711 # quiet Don't output some diagnostics, and set rc_quiet=yes
713 # The following globals are used:
715 # Name Needed Purpose
716 # ---- ------ -------
717 # name y Name of script.
719 # command n Full path to command.
720 # Not needed if ${rc_arg}_cmd is set for
723 # command_args n Optional args/shell directives for command.
725 # command_interpreter n If not empty, command is interpreted, so
726 # call check_{pidfile,process}() appropriately.
728 # desc n Description of script.
730 # extra_commands n List of extra commands supported.
732 # pidfile n If set, use check_pidfile $pidfile $command,
733 # otherwise use check_process $command.
734 # In either case, only check if $command is set.
736 # procname n Process name to check for instead of $command.
738 # rcvar n This is checked with checkyesno to determine
739 # if the action should be run.
741 # ${name}_program n Full path to command.
742 # Meant to be used in /etc/rc.conf to override
745 # ${name}_chroot n Directory to chroot to before running ${command}
746 # Requires /usr to be mounted.
748 # ${name}_chdir n Directory to cd to before running ${command}
749 # (if not using ${name}_chroot).
751 # ${name}_flags n Arguments to call ${command} with.
752 # NOTE: $flags from the parent environment
753 # can be used to override this.
755 # ${name}_env n Environment variables to run ${command} with.
757 # ${name}_fib n Routing table number to run ${command} with.
759 # ${name}_nice n Nice level to run ${command} at.
761 # ${name}_oomprotect n Don't kill ${command} when swap space is exhausted.
763 # ${name}_user n User to run ${command} as, using su(1) if not
764 # using ${name}_chroot.
765 # Requires /usr to be mounted.
767 # ${name}_group n Group to run chrooted ${command} as.
768 # Requires /usr to be mounted.
770 # ${name}_groups n Comma separated list of supplementary groups
771 # to run the chrooted ${command} with.
772 # Requires /usr to be mounted.
774 # ${name}_prepend n Command added before ${command}.
776 # ${name}_login_class n Login class to use, else "daemon".
778 # ${rc_arg}_cmd n If set, use this as the method when invoked;
779 # Otherwise, use default command (see below)
781 # ${rc_arg}_precmd n If set, run just before performing the
782 # ${rc_arg}_cmd method in the default
783 # operation (i.e, after checking for required
784 # bits and process (non)existence).
785 # If this completes with a non-zero exit code,
786 # don't run ${rc_arg}_cmd.
788 # ${rc_arg}_postcmd n If set, run just after performing the
789 # ${rc_arg}_cmd method, if that method
790 # returned a zero exit code.
792 # required_dirs n If set, check for the existence of the given
793 # directories before running a (re)start command.
795 # required_files n If set, check for the readability of the given
796 # files before running a (re)start command.
798 # required_modules n If set, ensure the given kernel modules are
799 # loaded before running a (re)start command.
800 # The check and possible loads are actually
801 # done after start_precmd so that the modules
802 # aren't loaded in vain, should the precmd
803 # return a non-zero status to indicate a error.
804 # If a word in the list looks like "foo:bar",
805 # "foo" is the KLD file name and "bar" is the
806 # module name. If a word looks like "foo~bar",
807 # "foo" is the KLD file name and "bar" is a
808 # egrep(1) pattern matching the module name.
809 # Otherwise the module name is assumed to be
810 # the same as the KLD file name, which is most
811 # common. See load_kld().
813 # required_vars n If set, perform checkyesno on each of the
814 # listed variables before running the default
817 # Default behaviour for a given argument, if no override method is
820 # Argument Default behaviour
821 # -------- -----------------
822 # start if !running && checkyesno ${rcvar}
826 # rc_pid=$(check_pidfile $pidfile $command)
828 # rc_pid=$(check_process $command)
829 # kill $sig_stop $rc_pid
830 # wait_for_pids $rc_pid
831 # ($sig_stop defaults to TERM.)
833 # reload Similar to stop, except use $sig_reload instead,
834 # and doesn't wait_for_pids.
835 # $sig_reload defaults to HUP.
836 # Note that `reload' isn't provided by default,
837 # it should be enabled via $extra_commands.
839 # restart Run `stop' then `start'.
841 # status Show if ${command} is running, etc.
843 # poll Wait for ${command} to exit.
845 # rcvar Display what rc.conf variable is used (if any).
847 # enabled Return true if the service is enabled.
849 # describe Show the service's description
851 # extracommands Show the service's extra commands
853 # Variables available to methods, and after run_rc_command() has
858 # rc_arg Argument to command, after fast/force/one processing
861 # rc_flags Flags to start the default command with.
862 # Defaults to ${name}_flags, unless overridden
863 # by $flags from the environment.
864 # This variable may be changed by the precmd method.
866 # rc_pid PID of command (if appropriate)
868 # rc_fast Not empty if "fast" was provided (q.v.)
870 # rc_force Not empty if "force" was provided (q.v.)
872 # rc_quiet Not empty if "quiet" was provided
879 if [ -z "$name" ]; then
880 err 3 'run_rc_command: $name is not set.'
883 # Don't repeat the first argument when passing additional command-
884 # line arguments to the command subroutines.
891 fast*) # "fast" prefix; don't check pid
892 rc_arg=${rc_arg#fast}
896 force*) # "force" prefix; always run
899 rc_arg=${rc_arg#${_rc_prefix}}
900 if [ -n "${rcvar}" ]; then
904 one*) # "one" prefix; set ${rcvar}=yes
906 rc_arg=${rc_arg#${_rc_prefix}}
907 if [ -n "${rcvar}" ]; then
911 quiet*) # "quiet" prefix; omit some messages
913 rc_arg=${rc_arg#${_rc_prefix}}
918 eval _override_command=\$${name}_program
919 command=${_override_command:-$command}
921 _keywords="start stop restart rcvar enabled describe extracommands $extra_commands"
924 _procname=${procname:-${command}}
926 # setup pid check command
927 if [ -n "$_procname" ]; then
928 if [ -n "$pidfile" ]; then
929 _pidcmd='rc_pid=$(check_pidfile '"$pidfile $_procname $command_interpreter"')'
931 _pidcmd='rc_pid=$(check_process '"$_procname $command_interpreter"')'
933 _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
1050 ${_nice:+nice -n $_nice }\
1051 ${_fib:+setfib -F $_fib }\
1052 ${_env:+env $_env }\
1053 chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
1054 $_chroot $command $rc_flags $command_args"
1056 _cd="${_chdir:+cd $_chdir && }"
1058 ${_fib:+setfib -F $_fib }\
1059 ${_env:+env $_env }\
1060 $command $rc_flags $command_args"
1061 if [ -n "$_user" ]; then
1062 _doit="su -m $_user -c 'sh -c \"$_doit\"'"
1064 if [ -n "$_nice" ]; then
1065 if [ -z "$_user" ]; then
1066 _doit="sh -c \"$_doit\""
1068 _doit="nice -n $_nice $_doit"
1070 if [ -n "$_prepend" ]; then
1071 _doit="$_prepend $_doit"
1075 # Prepend default limits
1076 _doit="$_cd limits -C $_login_class $_doit"
1078 # run the full command
1080 if ! _run_rc_doit "$_doit"; then
1081 warn "failed to start ${name}"
1085 # finally, run postcmd
1091 if [ -z "$rc_pid" ]; then
1092 [ -n "$rc_fast" ] && return 0
1097 _run_rc_precmd || return 1
1099 # send the signal to stop
1101 echo "Stopping ${name}."
1102 _doit=$(_run_rc_killcmd "${sig_stop:-TERM}")
1103 _run_rc_doit "$_doit" || return 1
1105 # wait for the command to exit,
1107 wait_for_pids $rc_pid
1113 if [ -z "$rc_pid" ]; then
1118 _run_rc_precmd || return 1
1120 _doit=$(_run_rc_killcmd "${sig_reload:-HUP}")
1121 _run_rc_doit "$_doit" || return 1
1127 # prevent restart being called more
1128 # than once by any given script
1130 if ${_rc_restart_done:-false}; then
1133 _rc_restart_done=true
1135 _run_rc_precmd || return 1
1137 # run those in a subshell to keep global variables
1138 ( run_rc_command ${_rc_prefix}stop $rc_extra_args )
1139 ( run_rc_command ${_rc_prefix}start $rc_extra_args )
1141 [ $_return -ne 0 ] && [ -z "$rc_force" ] && return 1
1147 _run_rc_precmd || return 1
1148 if [ -n "$rc_pid" ]; then
1149 wait_for_pids $rc_pid
1156 if [ -n "$desc" ]; then
1162 # Get unique vars in $rcvar $rcvars
1163 for _v in $rcvar $rcvars; do
1165 $_v\ *|\ *$_v|*\ $_v\ *) ;;
1166 *) v="${v# } $_v" ;;
1170 # Display variables.
1172 if [ -z "$_v" ]; then
1176 eval _desc=\$${_v}_desc
1177 eval _defval=\$${_v}_defval
1180 eval echo \"$_v=\\\"\$$_v\\\"\"
1181 # decode multiple lines of _desc
1182 while [ -n "$_desc" ]; do
1185 echo "# $_h ${_desc%%^^*}"
1190 echo "# $_h ${_desc}"
1195 echo "# (default: \"$_defval\")"
1206 # Apply protect(1) to the PID if ${name}_oomprotect is set.
1209 # We cannot use protect(1) inside jails.
1210 if [ -n "$_oomprotect" ] && [ -f "${PROTECT}" ] &&
1211 [ "$(sysctl -n security.jail.jailed)" -eq 0 ]; then
1212 pid=$(check_process $command)
1213 case $_oomprotect in
1215 ${PROTECT} -i -p ${pid}
1218 ${PROTECT} -p ${pid}
1228 echo 1>&2 "$0: unknown directive '$rc_arg'."
1234 # Helper functions for run_rc_command: common code.
1235 # They use such global variables besides the exported rc_* ones:
1238 # ------------------
1245 check_required_before "$rc_arg" || return 1
1247 if [ -n "$_precmd" ]; then
1248 debug "run_rc_command: ${rc_arg}_precmd: $_precmd $rc_extra_args"
1249 eval "$_precmd $rc_extra_args"
1252 # If precmd failed and force isn't set, request exit.
1253 if [ $_return -ne 0 ] && [ -z "$rc_force" ]; then
1258 check_required_after "$rc_arg" || return 1
1265 if [ -n "$_postcmd" ]; then
1266 debug "run_rc_command: ${rc_arg}_postcmd: $_postcmd $rc_extra_args"
1267 eval "$_postcmd $rc_extra_args"
1275 debug "run_rc_command: doit: $*"
1279 # If command failed and force isn't set, request exit.
1280 if [ $_return -ne 0 ] && [ -z "$rc_force" ]; then
1287 _run_rc_notrunning()
1291 if [ -n "$pidfile" ]; then
1292 _pidmsg=" (check $pidfile)."
1296 echo 1>&2 "${name} not running?${_pidmsg}"
1303 _cmd="kill -$1 $rc_pid"
1304 if [ -n "$_user" ]; then
1305 _cmd="su -m ${_user} -c 'sh -c \"${_cmd}\"'"
1311 # run_rc_script file arg
1312 # Start the script `file' with `arg', and correctly handle the
1313 # return value from the script.
1314 # If `file' ends with `.sh' and lives in /etc/rc.d, ignore it as it's
1315 # an old-style startup file.
1316 # If `file' ends with `.sh' and does not live in /etc/rc.d, it's sourced
1317 # into the current environment if $rc_fast_and_loose is set; otherwise
1318 # it is run as a child process.
1319 # If `file' appears to be a backup or scratch file, ignore it.
1320 # Otherwise if it is executable run as a child process.
1326 if [ -z "$_file" -o -z "$_arg" ]; then
1327 err 3 'USAGE: run_rc_script file arg'
1330 unset name command command_args command_interpreter \
1331 extra_commands pidfile procname \
1332 rcvar rcvars rcvars_obsolete required_dirs required_files \
1334 eval unset ${_arg}_cmd ${_arg}_precmd ${_arg}_postcmd
1337 /etc/rc.d/*.sh) # no longer allowed in the base
1338 warn "Ignoring old-style startup script $_file"
1340 *[~#]|*.OLD|*.bak|*.orig|*,v) # scratch file; skip
1341 warn "Ignoring scratch file $_file"
1343 *) # run in subshell
1344 if [ -x $_file ]; then
1345 if [ -n "$rc_fast_and_loose" ]; then
1348 ( trap "echo Script $_file interrupted >&2 ; kill -QUIT $$" 3
1349 trap "echo Script $_file interrupted >&2 ; exit 1" 2
1350 trap "echo Script $_file running >&2" 29
1351 set $_arg; . $_file )
1359 # load_rc_config [service]
1360 # Source in the configuration file(s) for a given service.
1361 # If no service is specified, only the global configuration
1362 # file(s) will be loaded.
1366 local _name _rcvar_val _var _defval _v _msg _new _d
1369 if ${_rc_conf_loaded:-false}; then
1372 if [ -r /etc/defaults/rc.conf ]; then
1373 debug "Sourcing /etc/defaults/rc.conf"
1374 . /etc/defaults/rc.conf
1376 elif [ -r /etc/rc.conf ]; then
1377 debug "Sourcing /etc/rc.conf (/etc/defaults/rc.conf doesn't exist)."
1380 _rc_conf_loaded=true
1383 # If a service name was specified, attempt to load
1384 # service-specific configuration
1385 if [ -n "$_name" ] ; then
1386 for _d in /etc ${local_startup}; do
1388 if [ -f ${_d}/rc.conf.d/"$_name" ]; then
1389 debug "Sourcing ${_d}/rc.conf.d/$_name"
1390 . ${_d}/rc.conf.d/"$_name"
1391 elif [ -d ${_d}/rc.conf.d/"$_name" ] ; then
1393 for _rc in ${_d}/rc.conf.d/"$_name"/* ; do
1394 if [ -f "$_rc" ] ; then
1395 debug "Sourcing $_rc"
1403 # Set defaults if defined.
1404 for _var in $rcvar $rcvars; do
1405 eval _defval=\$${_var}_defval
1406 if [ -n "$_defval" ]; then
1407 eval : \${$_var:=\$${_var}_defval}
1411 # check obsolete rc.conf variables
1412 for _var in $rcvars_obsolete; do
1414 eval _msg=\$${_var}_obsolete_msg
1415 eval _new=\$${_var}_newvar
1420 if [ -z "$_new" ]; then
1423 eval $_new=\"\$$_var\"
1424 if [ -z "$_msg" ]; then
1425 _msg="Use \$$_new instead."
1428 warn "\$$_var is obsolete. $_msg"
1435 # load_rc_config_var name var
1436 # Read the rc.conf(5) var for name and set in the
1437 # current shell, using load_rc_config in a subshell to prevent
1438 # unwanted side effects from other variable assignments.
1440 load_rc_config_var()
1442 if [ $# -ne 2 ]; then
1443 err 3 'USAGE: load_rc_config_var name var'
1446 load_rc_config '$1' >/dev/null;
1447 if [ -n "${'$2'}" -o "${'$2'-UNSET}" != "UNSET" ]; then
1448 echo '$2'=\'\''${'$2'}\'\'';
1455 # Print a usage string for $0, with `commands' being a list of
1460 echo -n 1>&2 "Usage: $0 [fast|force|one|quiet]("
1464 echo -n 1>&2 "$_sep$_elem"
1472 # err exitval message
1473 # Display message to stderr and log to the syslog, and exit with exitval.
1480 if [ -x /usr/bin/logger ]; then
1481 logger "$0: ERROR: $*"
1483 echo 1>&2 "$0: ERROR: $*"
1489 # Display message to stderr and log to the syslog.
1493 if [ -x /usr/bin/logger ]; then
1494 logger "$0: WARNING: $*"
1496 echo 1>&2 "$0: WARNING: $*"
1501 # Display informational message to stdout and log to syslog.
1506 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
1507 if [ -x /usr/bin/logger ]; then
1508 logger "$0: INFO: $*"
1517 # If debugging is enabled in rc.conf output message to stderr.
1518 # BEWARE that you don't call any subroutine that itself calls this
1524 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
1525 if [ -x /usr/bin/logger ]; then
1526 logger "$0: DEBUG: $*"
1528 echo 1>&2 "$0: DEBUG: $*"
1534 # backup_file action file cur backup
1535 # Make a backup copy of `file' into `cur', and save the previous
1536 # version of `cur' as `backup'.
1538 # The `action' keyword can be one of the following:
1540 # add `file' is now being backed up (and is possibly
1541 # being reentered into the backups system). `cur'
1544 # update `file' has changed and needs to be backed up.
1545 # If `cur' exists, it is copied to to `back'
1546 # and then `file' is copied to `cur'.
1548 # remove `file' is no longer being tracked by the backups
1549 # system. `cur' is moved `back'.
1561 if [ -f $_cur ]; then
1565 chown root:wheel $_cur
1573 # make_symlink src link
1574 # Make a symbolic link 'link' to src from basedir. If the
1575 # directory in which link is to be created does not exist
1576 # a warning will be displayed and an error will be returned.
1577 # Returns 0 on success, 1 otherwise.
1581 local src link linkdir _me
1584 linkdir="`dirname $link`"
1585 _me="make_symlink()"
1587 if [ -z "$src" -o -z "$link" ]; then
1588 warn "$_me: requires two arguments."
1591 if [ ! -d "$linkdir" ]; then
1592 warn "$_me: the directory $linkdir does not exist."
1595 if ! ln -sf $src $link; then
1596 warn "$_me: unable to make a symbolic link from $link to $src"
1602 # devfs_rulesets_from_file file
1603 # Reads a set of devfs commands from file, and creates
1604 # the specified rulesets with their rules. Returns non-zero
1605 # if there was an error.
1607 devfs_rulesets_from_file()
1609 local file _err _me _opts
1611 _me="devfs_rulesets_from_file"
1614 if [ -z "$file" ]; then
1615 warn "$_me: you must specify a file"
1618 if [ ! -e "$file" ]; then
1619 debug "$_me: no such file ($file)"
1623 # Disable globbing so that the rule patterns are not expanded
1624 # by accident with matching filesystem entries.
1627 debug "reading rulesets from file ($file)"
1635 rulenum=`expr "$line" : "\[.*=\([0-9]*\)\]"`
1636 if [ -z "$rulenum" ]; then
1637 warn "$_me: cannot extract rule number ($line)"
1641 rulename=`expr "$line" : "\[\(.*\)=[0-9]*\]"`
1642 if [ -z "$rulename" ]; then
1643 warn "$_me: cannot extract rule name ($line)"
1647 eval $rulename=\$rulenum
1648 debug "found ruleset: $rulename=$rulenum"
1649 if ! /sbin/devfs rule -s $rulenum delset; then
1655 rulecmd="${line%%"\#*"}"
1656 # evaluate the command incase it includes
1658 if [ -n "$rulecmd" ]; then
1659 debug "adding rule ($rulecmd)"
1660 if ! eval /sbin/devfs rule -s $rulenum $rulecmd
1668 if [ $_err -ne 0 ]; then
1669 debug "error in $_me"
1673 case $_opts in *f*) ;; *) set +f ;; esac
1677 # devfs_init_rulesets
1678 # Initializes rulesets from configuration files. Returns
1679 # non-zero if there was an error.
1681 devfs_init_rulesets()
1684 _me="devfs_init_rulesets"
1686 # Go through this only once
1687 if [ -n "$devfs_rulesets_init" ]; then
1688 debug "$_me: devfs rulesets already initialized"
1691 for file in $devfs_rulesets; do
1692 if ! devfs_rulesets_from_file $file; then
1693 warn "$_me: could not read rules from $file"
1697 devfs_rulesets_init=1
1698 debug "$_me: devfs rulesets initialized"
1702 # devfs_set_ruleset ruleset [dir]
1703 # Sets the default ruleset of dir to ruleset. The ruleset argument
1704 # must be a ruleset name as specified in devfs.rules(5) file.
1705 # Returns non-zero if it could not set it successfully.
1710 [ -n "$1" ] && eval rs=\$$1 || rs=
1711 [ -n "$2" ] && devdir="-m "$2"" || devdir=
1712 _me="devfs_set_ruleset"
1714 if [ -z "$rs" ]; then
1715 warn "$_me: you must specify a ruleset number"
1718 debug "$_me: setting ruleset ($rs) on mount-point (${devdir#-m })"
1719 if ! /sbin/devfs $devdir ruleset $rs; then
1720 warn "$_me: unable to set ruleset $rs to ${devdir#-m }"
1726 # devfs_apply_ruleset ruleset [dir]
1727 # Apply ruleset number $ruleset to the devfs mountpoint $dir.
1728 # The ruleset argument must be a ruleset name as specified
1729 # in a devfs.rules(5) file. Returns 0 on success or non-zero
1730 # if it could not apply the ruleset.
1732 devfs_apply_ruleset()
1735 [ -n "$1" ] && eval rs=\$$1 || rs=
1736 [ -n "$2" ] && devdir="-m "$2"" || devdir=
1737 _me="devfs_apply_ruleset"
1739 if [ -z "$rs" ]; then
1740 warn "$_me: you must specify a ruleset"
1743 debug "$_me: applying ruleset ($rs) to mount-point (${devdir#-m })"
1744 if ! /sbin/devfs $devdir rule -s $rs applyset; then
1745 warn "$_me: unable to apply ruleset $rs to ${devdir#-m }"
1751 # devfs_domount dir [ruleset]
1752 # Mount devfs on dir. If ruleset is specified it is set
1753 # on the mount-point. It must also be a ruleset name as specified
1754 # in a devfs.rules(5) file. Returns 0 on success.
1760 [ -n "$2" ] && rs=$2 || rs=
1761 _me="devfs_domount()"
1763 if [ -z "$devdir" ]; then
1764 warn "$_me: you must specify a mount-point"
1767 debug "$_me: mount-point is ($devdir), ruleset is ($rs)"
1768 if ! mount -t devfs dev "$devdir"; then
1769 warn "$_me: Unable to mount devfs on $devdir"
1772 if [ -n "$rs" ]; then
1774 devfs_set_ruleset $rs $devdir
1775 devfs -m $devdir rule applyset
1780 # Provide a function for normalizing the mounting of memory
1781 # filesystems. This should allow the rest of the code here to remain
1782 # as close as possible between 5-current and 4-stable.
1785 # $3 = (optional) extra mdmfs flags
1788 if [ -n "$3" ]; then
1791 /sbin/mdmfs $flags -s $1 ${mfs_type} $2
1794 # Code common to scripts that need to load a kernel module
1795 # if it isn't in the kernel yet. Syntax:
1796 # load_kld [-e regex] [-m module] file
1797 # where -e or -m chooses the way to check if the module
1798 # is already loaded:
1799 # regex is egrep'd in the output from `kldstat -v',
1800 # module is passed to `kldstat -m'.
1801 # The default way is as though `-m file' were specified.
1804 local _loaded _mod _opt _re
1806 while getopts "e:m:" _opt; do
1809 m) _mod="$OPTARG" ;;
1810 *) err 3 'USAGE: load_kld [-e regex] [-m module] file' ;;
1813 shift $(($OPTIND - 1))
1814 if [ $# -ne 1 ]; then
1815 err 3 'USAGE: load_kld [-e regex] [-m module] file'
1819 if [ -n "$_re" ]; then
1820 if kldstat -v | egrep -q -e "$_re"; then
1824 if kldstat -q -m "$_mod"; then
1829 if ! kldload "$1"; then
1830 warn "Unable to load kernel module $1"
1833 info "$1 kernel module loaded."
1836 debug "load_kld: $1 kernel module already loaded."
1841 # ltr str src dst [var]
1842 # Change every $src in $str to $dst.
1843 # Useful when /usr is not yet mounted and we cannot use tr(1), sed(1) nor
1844 # awk(1). If var is non-NULL, set it to the result.
1847 local _str _src _dst _out _com _var
1855 for _com in ${_str}; do
1856 if [ -z "${_out}" ]; then
1859 _out="${_out}${_dst}${_com}"
1862 if [ -n "${_var}" ]; then
1863 setvar "${_var}" "${_out}"
1869 # Creates a list of providers for GELI encryption.
1872 local devices devices2
1873 local provider mountpoint type options rest
1875 # Create list of GELI providers from fstab.
1876 while read provider mountpoint type options rest ; do
1877 case ":${options}" in
1886 case ":${provider}" in
1891 # Skip swap devices.
1892 if [ "${type}" = "swap" -o "${options}" = "sw" -o "${noauto}" = "yes" ]; then
1895 devices="${devices} ${provider}"
1900 # Append providers from geli_devices.
1901 devices="${devices} ${geli_devices}"
1903 for provider in ${devices}; do
1904 provider=${provider%.eli}
1905 provider=${provider#/dev/}
1906 devices2="${devices2} ${provider}"
1912 # Originally, root mount hold had to be released before mounting
1913 # the root filesystem. This delayed the boot, so it was changed
1914 # to only wait if the root device isn't readily available. This
1915 # can result in rc scripts executing before all the devices - such
1916 # as graid(8), or USB disks - can be accessed. This function can
1917 # be used to explicitly wait for root mount holds to be released.
1920 local wait waited holders
1924 holders="$(sysctl -n vfs.root_mount_hold)"
1925 if [ -z "${holders}" ]; then
1928 if [ ${waited} -eq 0 ]; then
1929 echo -n "Waiting ${root_hold_delay}s" \
1930 "for the root mount holders: ${holders}"
1934 if [ ${waited} -ge ${root_hold_delay} ]; then
1939 waited=$(($waited + 1))
1943 # Find scripts in local_startup directories that use the old syntax
1945 find_local_scripts_old() {
1948 for dir in ${local_startup}; do
1949 if [ -d "${dir}" ]; then
1950 for file in ${dir}/[0-9]*.sh; do
1951 grep '^# PROVIDE:' $file >/dev/null 2>&1 &&
1953 zlist="$zlist $file"
1955 for file in ${dir}/[!0-9]*.sh; do
1956 grep '^# PROVIDE:' $file >/dev/null 2>&1 &&
1958 slist="$slist $file"
1964 find_local_scripts_new() {
1966 for dir in ${local_startup}; do
1967 if [ -d "${dir}" ]; then
1968 for file in `grep -l '^# PROVIDE:' ${dir}/* 2>/dev/null`; do
1971 *) if [ -x "$file" ]; then
1972 local_rc="${local_rc} ${file}"
1981 # check_required_{before|after} command
1982 # Check for things required by the command before and after its precmd,
1983 # respectively. The two separate functions are needed because some
1984 # conditions should prevent precmd from being run while other things
1985 # depend on precmd having already been run.
1987 check_required_before()
1993 for _f in $required_vars; do
1994 if ! checkyesno $_f; then
1995 warn "\$${_f} is not enabled."
1996 if [ -z "$rc_force" ]; then
2002 for _f in $required_dirs; do
2003 if [ ! -d "${_f}/." ]; then
2004 warn "${_f} is not a directory."
2005 if [ -z "$rc_force" ]; then
2011 for _f in $required_files; do
2012 if [ ! -r "${_f}" ]; then
2013 warn "${_f} is not readable."
2014 if [ -z "$rc_force" ]; then
2025 check_required_after()
2031 for _f in $required_modules; do
2033 *~*) _args="-e ${_f#*~} ${_f%%~*}" ;;
2034 *:*) _args="-m ${_f#*:} ${_f%%:*}" ;;
2037 if ! load_kld ${_args}; then
2038 if [ -z "$rc_force" ]; then
2050 # Return true if security.jail.$mib exists and set to 1.
2057 if _v=$(${SYSCTL_N} "security.jail.$_mib" 2> /dev/null); then
2065 # check_kern_features mib
2066 # Return existence of kern.features.* sysctl MIB as true or
2067 # false. The result will be cached in $_rc_cache_kern_features_
2068 # namespace. "0" means the kern.features.X exists.
2070 check_kern_features()
2074 [ -n "$1" ] || return 1;
2075 eval _v=\$_rc_cache_kern_features_$1
2076 [ -n "$_v" ] && return "$_v";
2078 if ${SYSCTL_N} kern.features.$1 > /dev/null 2>&1; then
2079 eval _rc_cache_kern_features_$1=0
2082 eval _rc_cache_kern_features_$1=1
2087 # check_namevarlist var
2088 # Return "0" if ${name}_var is reserved in rc.subr.
2090 _rc_namevarlist="program chroot chdir env flags fib nice user group groups prepend"
2095 for _v in $_rc_namevarlist; do
2104 # _echoonce var msg mode
2105 # mode=0: Echo $msg if ${$var} is empty.
2106 # After doing echo, a string is set to ${$var}.
2108 # mode=1: Echo $msg if ${$var} is a string with non-zero length.
2112 local _var _msg _mode
2118 1) [ -n "$_var" ] && echo "$_msg" ;;
2119 *) [ -z "$_var" ] && echo -n "$_msg" && eval "$1=finished" ;;
2123 # If the loader env variable rc.debug is set, turn on debugging. rc.conf will
2124 # still override this, but /etc/defaults/rc.conf can't unconditionally set this
2125 # since it would undo what we've done here.
2126 if kenv -q rc.debug > /dev/null ; then