1 # $NetBSD: rc.subr,v 1.49 2002/05/21 12:31:01 lukem Exp $
2 # $FreeBSD: src/etc/rc.subr,v 1.13 2003/06/09 17:31:06 mtm Exp $
3 # $DragonFly: src/etc/rc.subr,v 1.15 2008/04/05 08:07:11 matthias Exp $
5 # Copyright (c) 1997-2002 The NetBSD Foundation, Inc.
8 # This code is derived from software contributed to The NetBSD Foundation
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 # 3. All advertising materials mentioning features or use of this software
20 # must display the following acknowledgement:
21 # This product includes software developed by the NetBSD
22 # Foundation, Inc. and its contributors.
23 # 4. Neither the name of The NetBSD Foundation nor the names of its
24 # contributors may be used to endorse or promote products derived
25 # from this software without specific prior written permission.
27 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 # POSSIBILITY OF SUCH DAMAGE.
40 # functions used by various rc scripts
44 # Operating System dependent/independent variables
47 if [ "X$_file" = "X" ]; then
51 provide_list=`rcorder -p $_file`
54 SYSCTL_N="${SYSCTL} -n"
55 CMD_OSTYPE="${SYSCTL_N} kern.ostype"
56 OSTYPE=`${CMD_OSTYPE}`
72 # Set the variable name enabling a specific service.
73 # FreeBSD uses ${service}_enable, while NetBSD uses
74 # just the name of the service. For example:
75 # FreeBSD: sendmail_enable="YES"
76 # NetBSD : sendmail="YES"
77 # $1 - if $name is not the base to work of off, specify
93 # $1 should be $rc_arg (start, stop, restart, reload, etc)
94 # $2 return value $RC_*
96 # Set the rcng_* variables associated with elements in provide_list
99 # Returns non-zero when early termination should occur, in which
100 # case the caller should return with a value of $? - 1
104 # Remember, plret is set to the early termination return code + 1,
105 # or 0 if we want to continue the operation.
107 for i in $provide_list; do
109 start$RC_RUNNING|restart$RC_RUNNING)
110 varsym -s rcng_$i=running
112 start$RC_FAILED|restart$RC_FAILED)
113 varsym -s rcng_$i=failed
115 start$RC_DISABLED|restart$RC_DISABLED|reload$RC_DISABLED)
116 varsym -s rcng_$i=disabled
118 start$RC_IRRELEVANT|restart$RC_IRRELEVANT|reload$RC_IRRELEVANT)
119 varsym -s rcng_$i=irrelevant
121 start$RC_CONFIGURED|restart$RC_CONFIGURED)
122 varsym -s rcng_$i=configured
125 varsym -s rcng_$i=disabled
128 varsym -s rcng_$i=irrelevant
131 varsym -s rcng_$i=stopped
140 # $1 should be $rc_arg (start, stop, restart, reload, etc)
141 # $2 return value $RC_*
142 # $3 $rc_force "" not to force, "anything" to force.
144 # The return code is 0 if early termination is not to occur, non-zero if
145 # it is to occur. When early termination is to occur the caller should
146 # return check_early_term()'s return code - 1. That is, early termination
147 # can occur with or without an error.
149 # The provide list will be adjusted when early termination occurs.
158 set_provide_list $1 $2
159 [ -z "$3" ] || return 0
163 set_provide_list $1 $2
164 [ -z "$3" ] || return 0
168 set_provide_list $1 $2
169 [ -z "$3" ] || return 0
179 set_provide_list $1 $2
180 [ -z "$3" ] || return 0
184 # adjust_return_code $1
186 # Convert the return code to an exit code of 0 (success) or 1 (failure)
190 if [ $1 = $RC_FAILED ]; then
197 # force_depend script
198 # Force a service to start. Intended for use by services
199 # to resolve dependency issues. It is assumed the caller
200 # has check to make sure this call is necessary
201 # $1 - filename of script, in /etc/rc.d, to run
207 info "${name} depends on ${_depend}, which will be forced to start."
208 if ! /etc/rc.d/${_depend} forcestart ; then
209 warn "Unable to force ${_depend}. It may already be running."
217 # Test $1 variable, and warn if not set to YES or NO.
218 # Return 0 if it's "yes" (et al), nonzero otherwise.
223 eval _value=\$${1%_enable}
227 eval _value=\$${1%_enable}_enable;
229 debug "checkyesno: $1 is set to $_value."
232 # "yes", "true", "on", or "1"
233 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
237 # "no", "false", "off", or "0"
238 [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
242 warn "\$${1} is not set properly - see rc.conf(5)."
249 # print the list in reverse order
254 for _revfile in $*; do
255 _revlist="$_revfile $_revlist"
261 # mount_critical_filesystems type
262 # Go through the list of critical filesystems as provided in
263 # the rc.conf(5) variable $critical_filesystems_${type}, checking
264 # each one to see if it is mounted, and if it is not, mounting it.
266 mount_critical_filesystems()
268 eval _fslist=\$critical_filesystems_${1}
269 for _fs in $_fslist; do
272 while read what _on on _type type; do
273 if [ $on = $_fs ]; then
277 if [ $_ismounted = no ]; then
278 mount $_fs >/dev/null 2>&1
285 # check_pidfile pidfile procname [interpreter]
286 # Parses the first line of pidfile for a PID, and ensures
287 # that the process is running and matches procname.
288 # Prints the matching PID upon success, nothing otherwise.
289 # interpreter is optional; see _find_processes() for details.
296 if [ -z "$_pidfile" -o -z "$_procname" ]; then
297 err 3 'USAGE: check_pidfile pidfile procname [interpreter]'
299 if [ ! -f $_pidfile ]; then
300 debug "pid file {$_pidfile): not readable."
303 read _pid _junk < $_pidfile
304 if [ -z "$_pid" ]; then
305 debug "pid file {$_pidfile): no pid in file."
308 _find_processes $_procname ${_interpreter:-.} '-p '"$_pid"
312 # check_process procname [interpreter]
313 # Ensures that a process (or processes) named procname is running.
314 # Prints a list of matching PIDs.
315 # interpreter is optional; see _find_processes() for details.
321 if [ -z "$_procname" ]; then
322 err 3 'USAGE: check_process procname [interpreter]'
324 _find_processes $_procname ${_interpreter:-.} '-ax'
328 # _find_processes procname interpreter psargs
329 # Search for procname in the output of ps generated by psargs.
330 # Prints the PIDs of any matching processes, space separated.
332 # If interpreter == ".", check the following variations of procname
333 # against the first word of each command:
335 # `basename procname`
336 # `basename procname` + ":"
337 # "(" + `basename procname` + ")"
339 # If interpreter != ".", read the first line of procname, remove the
340 # leading #!, normalise whitespace, append procname, and attempt to
341 # match that against each command, either as is, or with extra words
346 if [ $# -ne 3 ]; then
347 err 3 'USAGE: _find_processes procname interpreter psargs'
354 if [ $_interpreter != "." ]; then # an interpreted script
355 read _interp < $_procname # read interpreter name
356 _interp=${_interp#\#!} # strip #!
358 if [ $_interpreter != $1 ]; then
359 warn "\$command_interpreter $_interpreter != $1"
361 _interp="$* $_procname" # cleanup spaces, add _procname
362 _interpbn="$1" # the interpreter binary
364 _fp_match='case "$_argv" in
365 "${_interpbn##*/}: "$_procname*|${_interp}|"${_interp} "*)'
366 else # a normal daemon
367 _procnamebn=${_procname##*/}
368 _fp_args='_arg0 _argv'
369 _fp_match='case "$_arg0" in
370 $_procname|$_procnamebn|${_procnamebn}:|"(${_procnamebn})")'
374 ps -o "pid,command" '"$_psargs"' |
375 while read _npid '"$_fp_args"'; do
379 esac ; '"$_fp_match"'
380 echo -n "$_pref$_npid" ;
386 # debug "in _find_processes: proccheck is ($_proccheck)."
391 # wait_for_pids pid [pid ...]
392 # spins until none of the pids exist
397 if [ -z "$_list" ]; then
404 if kill -0 $_j 2>/dev/null; then
405 _nlist="${_nlist}${_nlist:+ }$_j"
408 if [ -z "$_nlist" ]; then
412 echo -n ${_prefix:-"Waiting for PIDS: "}$_list
416 if [ -n "$_prefix" ]; then
422 # run_rc_command argument
423 # Search for argument in the list of supported commands, which is:
424 # "start stop restart rcvar status poll ${extra_commands}"
425 # If there's a match, run ${argument}_cmd or the default method
428 # If argument has a given prefix, then change the operation as follows:
431 # fast Skip the pid check, and set rc_fast=yes
432 # force Set ${rcvar} to YES, and set rc_force=yes
434 # The following globals are used:
436 # Name Needed Purpose
437 # ---- ------ -------
438 # provide_list (gen) list of keywords provided by current rcng file
440 # name y Name of script.
442 # command n Full path to command.
443 # Not needed if ${rc_arg}_cmd is set for
446 # command_args n Optional args/shell directives for command.
448 # command_interpreter n If not empty, command is interpreted, so
449 # call check_{pidfile,process}() appropriately.
451 # extra_commands n List of extra commands supported.
453 # pidfile n If set, use check_pidfile $pidfile $command,
454 # otherwise use check_process $command.
455 # In either case, only check if $command is set.
457 # procname n Process name to check for instead of $command.
459 # rcvar n This is checked with checkyesno to determine
460 # if the action should be run.
462 # ${name}_chroot n Directory to chroot to before running ${command}
463 # Requires /usr to be mounted.
465 # ${name}_chdir n Directory to cd to before running ${command}
466 # (if not using ${name}_chroot).
468 # ${name}_flags n Arguments to call ${command} with.
469 # NOTE: $flags from the parent environment
470 # can be used to override this.
472 # ${name}_nice n Nice level to run ${command} at.
474 # ${name}_user n User to run ${command} as, using su(1) if not
475 # using ${name}_chroot.
476 # Requires /usr to be mounted.
478 # ${name}_group n Group to run chrooted ${command} as.
479 # Requires /usr to be mounted.
481 # ${name}_groups n Comma separated list of supplementary groups
482 # to run the chrooted ${command} with.
483 # Requires /usr to be mounted.
485 # ${rc_arg}_cmd n If set, use this as the method when invoked;
486 # Otherwise, use default command (see below)
488 # ${rc_arg}_precmd n If set, run just before performing the
489 # ${rc_arg}_cmd method in the default
490 # operation (i.e, after checking for required
491 # bits and process (non)existence).
492 # If this completes with a non-zero exit code,
493 # don't run ${rc_arg}_cmd.
495 # ${rc_arg}_postcmd n If set, run just after performing the
496 # ${rc_arg}_cmd method, if that method
497 # returned a zero exit code.
499 # required_dirs n If set, check for the existence of the given
500 # directories before running the default
503 # required_files n If set, check for the readability of the given
504 # files before running the default (re)start
507 # required_vars n If set, perform checkyesno on each of the
508 # listed variables before running the default
511 # Default behaviour for a given argument, if no override method is
514 # Argument Default behaviour
515 # -------- -----------------
516 # start if !running && checkyesno ${rcvar}
520 # rc_pid=$(check_pidfile $pidfile $command)
522 # rc_pid=$(check_process $command)
523 # kill $sig_stop $rc_pid
524 # wait_for_pids $rc_pid
525 # ($sig_stop defaults to TERM.)
527 # reload Similar to stop, except use $sig_reload instead,
528 # and doesn't wait_for_pids.
529 # $sig_reload defaults to HUP.
531 # restart Run `stop' then `start'.
533 # status Show if ${command} is running, etc.
535 # poll Wait for ${command} to exit.
537 # rcvar Display what rc.conf variable is used (if any).
539 # Variables available to methods, and after run_rc_command() has
544 # rc_arg Argument to command, after fast/force processing
547 # rc_flags Flags to start the default command with.
548 # Defaults to ${name}_flags, unless overridden
549 # by $flags from the environment.
550 # This variable may be changed by the precmd method.
552 # rc_pid PID of command (if appropriate)
554 # rc_fast Not empty if "fast" was provided (q.v.)
556 # rc_force Not empty if "force" was provided (q.v.)
564 fast*) # "fast" prefix; don't check pid
565 rc_arg=${rc_arg#fast}
567 force*) # "force prefix; always start
568 rc_arg=${rc_arg#force}
571 set_provide_list $rc_arg $RC_CONFIGURED
579 if [ -z "$name" ]; then
580 err 3 'run_rc_command: $name is not set.'
584 fast*) # "fast" prefix; don't check pid
585 rc_arg=${rc_arg#fast}
588 force*) # "force prefix; always start
589 rc_arg=${rc_arg#force}
591 if [ -n "${rcvar}" ]; then
597 eval _override_command=\$${name}_program
598 if [ -n "$_override_command" ]; then
599 command=$_override_command
602 _keywords="start stop restart rcvar $extra_commands"
605 _procname=${procname:-${command}}
607 # setup pid check command if not fast
608 if [ -z "$rc_fast" -a -n "$_procname" ]; then
609 if [ -n "$pidfile" ]; then
610 _pidcmd='rc_pid=$(check_pidfile '"$pidfile $_procname $command_interpreter"')'
612 _pidcmd='rc_pid=$(check_process '"$_procname $command_interpreter"')'
614 if [ -n "$_pidcmd" ]; then
615 _keywords="${_keywords} status poll"
619 if [ -z "$rc_arg" ]; then
620 rc_usage "$_keywords"
623 if [ -n "$flags" ]; then # allow override from environment
626 eval rc_flags=\$${name}_flags
628 eval _chdir=\$${name}_chdir _chroot=\$${name}_chroot \
629 _nice=\$${name}_nice _user=\$${name}_user \
630 _group=\$${name}_group _groups=\$${name}_groups
632 if [ -n "$_user" ]; then # unset $_user if running as that user
633 if [ "$_user" = "$(id -un)" ]; then
638 # if ${rcvar} is set, and $1 is not
640 # checkyesno ${rcvar}
641 # and return if that failed
643 if [ -n "${rcvar}" -a "$rc_arg" != "rcvar" ]; then
644 if ! checkyesno ${rcvar}; then
645 set_provide_list $rc_arg $RC_DISABLED
650 eval $_pidcmd # determine the pid if necessary
652 for _elem in $_keywords; do
653 if [ "$_elem" != "$rc_arg" ]; then
657 # if there's a custom ${XXX_cmd},
658 # run that instead of the default
660 eval _cmd=\$${rc_arg}_cmd _precmd=\$${rc_arg}_precmd \
661 _postcmd=\$${rc_arg}_postcmd
662 if [ -n "$_cmd" ]; then
663 # if the precmd failed and force
666 if [ -n "$_precmd" ]; then
667 debug "run_rc_command: evaluating ${_precmd}()."
671 check_early_term $rc_arg $_return "$rc_force" || return $(($?-1))
674 if [ -n "$_cmd" ]; then
675 debug "run_rc_command: evaluating ${_cmd}()."
678 check_early_term $rc_arg $_return "$rc_force" || return $(($?-1))
681 if [ -n "$_postcmd" ]; then
682 debug "run_rc_command: evaluating ${_postcmd}()."
685 check_early_term $rc_arg $_return "" || return $(($?-1))
687 set_provide_list $rc_arg $_return
688 adjust_return_code $_return
692 case "$rc_arg" in # default operations...
695 if [ -n "$rc_pid" ]; then
696 echo "${name} is running as pid $rc_pid."
698 echo "${name} is not running."
704 if [ -n "$rc_pid" ]; then
705 echo "${name} already running? (pid=$rc_pid)."
709 if [ ! -x $command ]; then
710 info "run_rc_command: cannot run ($command)."
711 set_provide_list $rc_arg $RC_FAILED
712 adjust_return_code $RC_FAILED
716 # check for required variables,
717 # directories, and files
719 for _f in $required_vars; do
720 if ! checkyesno $_f; then
721 warn "\$${_f} is not set."
722 if [ -z "$rc_force" ]; then
723 set_provide_list $rc_arg $RC_FAILED
724 adjust_return_code $RC_FAILED
729 for _f in $required_dirs; do
730 if [ ! -d "${_f}/." ]; then
731 warn "${_f} is not a directory."
732 if [ -z "$rc_force" ]; then
733 set_provide_list $rc_arg $RC_FAILED
734 adjust_return_code $RC_FAILED
739 for _f in $required_files; do
740 if [ ! -r "${_f}" ]; then
741 warn "${_f} is not readable."
742 if [ -z "$rc_force" ]; then
743 set_provide_list $rc_arg $RC_FAILED
744 adjust_return_code $RC_FAILED
750 # if the precmd failed and force
753 if [ -n "${_precmd}" ]; then
754 debug "run_rc_command: evaluating ${_precmd}()."
757 check_early_term $rc_arg $_return "$rc_force" || return $(($?-1))
760 # setup the command to run, and run it
762 echo "Starting ${name}."
763 if [ -n "$_chroot" ]; then
765 ${_nice:+nice -n $_nice }\
766 chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
767 $_chroot $command $rc_flags $command_args"
770 ${_chdir:+cd $_chdir; }\
771 ${_nice:+nice -n $_nice }\
772 $command $rc_flags $command_args"
773 if [ -n "$_user" ]; then
774 _doit="su -m $_user -c 'sh -c \"$_doit\"'"
778 # if the cmd failed and force
781 debug "run_rc_command: _doit: $_doit"
784 check_early_term $rc_arg $_return "$rc_force" || return $(($?-1))
785 # finally, run postcmd
787 if [ -n "${_postcmd}" ]; then
788 debug "run_rc_command: evaluating ${_postcmd}()."
794 if [ -z "$rc_pid" ]; then
795 if [ -n "$pidfile" ]; then
797 "${name} not running? (check $pidfile)."
799 echo "${name} not running?"
801 set_provide_list $rc_arg $RC_STOPPED
805 # if the precmd failed and force
808 if [ -n $_precmd ]; then
811 check_early_term $rc_arg $_return "$rc_force" || return $(($?-1))
814 # send the signal to stop
816 echo "Stopping ${name}."
817 _doit="kill -${sig_stop:-TERM} $rc_pid"
818 if [ -n "$_user" ]; then
819 _doit="su -m $_user -c 'sh -c \"$_doit\"'"
822 # if the stop cmd failed and force
827 check_early_term $rc_arg $_return "$rc_force" || return $(($?-1))
828 # wait for the command to exit,
831 wait_for_pids $rc_pid
832 if [ -n "$_postcmd" ]; then
839 if [ -z "$rc_pid" ]; then
840 if [ -n "$pidfile" ]; then
842 "${name} not running? (check $pidfile)."
844 echo "${name} not running?"
846 set_provide_list $rc_arg $RC_FAILED
849 echo "Reloading ${name} config files."
850 if [ -n "$_precmd" ]; then
853 check_early_term $rc_arg $_return "$rc_force" || return $(($?-1))
855 _doit="kill -${sig_reload:-HUP} $rc_pid"
856 if [ -n "$_user" ]; then
857 _doit="su -m $_user -c 'sh -c \"$_doit\"'"
861 check_early_term $rc_arg $_return "$rc_force" || return $(($?-1))
862 if [ -n "$_postcmd" ]; then
869 if [ -n "$_precmd" ]; then
872 check_early_term $rc_arg $_return "$rc_force" || return $(($?-1))
874 # prevent restart being called more
875 # than once by any given script
877 if [ -n "$_rc_restart_done" ]; then
882 ( $0 ${rc_force:+force}stop )
883 $0 ${rc_force:+force}start
886 if [ -n "$_postcmd" ]; then
888 adjust_return_code $?
891 # Do not set_provide_list(), the start command above
892 # will have done it for us and we do not know the
893 # actual RC code to base a setting on here.
899 if [ -n "$rc_pid" ]; then
900 wait_for_pids $rc_pid
906 if [ -n "$rcvar" ]; then
907 if checkyesno ${rcvar}; then
908 echo "\$${rcvar}=YES"
916 rc_usage "$_keywords"
920 set_provide_list $rc_arg $_return
921 adjust_return_code $_return
925 echo 1>&2 "$0: unknown directive '$rc_arg'."
926 rc_usage "$_keywords"
931 # run_rc_script file arg
932 # Start the script `file' with `arg', and correctly handle the
933 # return value from the script. If `file' ends with `.sh', it's
934 # sourced into the current environment. If `file' appears to be
935 # a backup or scratch file, ignore it. Otherwise if it's
936 # executable run as a child process.
942 if [ -z "$_file" -o -z "$_arg" ]; then
943 err 3 'USAGE: run_rc_script file arg'
946 trap "echo 'Reboot interrupted'; exit 1" 3
948 unset name command command_args command_interpreter \
949 extra_commands pidfile procname \
950 rcvar required_dirs required_files required_vars
951 eval unset ${_arg}_cmd ${_arg}_precmd ${_arg}_postcmd
954 *.sh) # run in current shell
957 *[~#]|*.OLD|*.orig) # scratch file; skip
958 warn "Ignoring scratch file $_file"
961 if [ -x $_file ]; then
962 if [ -n "$rc_fast_and_loose" ]; then
965 ( trap "echo 'Reboot interrupted'; exit 1" 3
966 set $_arg ; . $_file )
974 # Change every $src in $str to $dst.
975 # Useful when /usr is not yet mounted and we cannot use tr(1), sed(1) nor
979 local _str _src _dst _out _com
986 for _com in ${_str}; do
987 if [ -z "${_out}" ]; then
990 _out="${_out}${_dst}${_com}"
998 # Source in the configuration file for a given command.
1003 if [ -z "$_command" ]; then
1004 err 3 'USAGE: load_rc_config command'
1007 if [ -z "$_rc_conf_loaded" ]; then
1008 if [ -r /etc/defaults/rc.conf ]; then
1009 debug "Sourcing /etc/defaults/rc.conf"
1010 . /etc/defaults/rc.conf
1012 elif [ -r /etc/rc.conf ]; then
1013 debug "Sourcing /etc/rc.conf (/etc/defaults/rc.conf doesn't exist)."
1018 if [ -f /etc/rc.conf.d/"$_command" ]; then
1019 debug "Sourcing /etc/rc.conf.d/${_command}"
1020 . /etc/rc.conf.d/"$_command"
1023 # XXX - Deprecated variable name support
1025 [ -n "$portmap_enable" ] && rpcbind_enable="$portmap_enable"
1026 [ -n "$portmap_program" ] && rpcbind_program="$portmap_program"
1027 [ -n "$portmap_flags" ] && rpcbind_flags="$portmap_flags"
1028 [ -n "$single_mountd_enable" ] && mountd_enable="$single_mountd_enable"
1029 [ -n "$dhcp_program" ] && dhclient_program="$dhcp_program"
1030 [ -n "$dhcp_flags" ] && dhclient_flags="$dhcp_flags"
1036 # Print a usage string for $0, with `commands' being a list of
1041 echo -n 1>&2 "Usage: $0 [fast|force]("
1045 echo -n 1>&2 "$_sep$_elem"
1053 # err exitval message
1054 # Display message to stderr and log to the syslog, and exit with exitval.
1061 if [ -x /usr/bin/logger ]; then
1062 logger "$0: ERROR: $*"
1064 echo 1>&2 "$0: ERROR: $*"
1070 # Display message to stderr and log to the syslog.
1074 if [ -x /usr/bin/logger ]; then
1075 logger "$0: WARNING: $*"
1077 echo 1>&2 "$0: WARNING: $*"
1082 # Display informational message to stdout and log to syslog.
1087 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
1088 if [ -x /usr/bin/logger ]; then
1089 logger "$0: INFO: $*"
1098 # If debugging is enabled in rc.conf output message to stderr.
1099 # BEWARE that you don't call any subroutine that itself calls this
1105 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
1106 if [ -x /usr/bin/logger ]; then
1107 logger "$0: INFO: $*"
1109 echo 1>&2 "$0: DEBUG: $*"
1115 # backup_file action file cur backup
1116 # Make a backup copy of `file' into `cur', and save the previous
1117 # version of `cur' as `backup' or use rcs for archiving.
1119 # This routine checks the value of the backup_uses_rcs variable,
1120 # which can be either YES or NO.
1122 # The `action' keyword can be one of the following:
1124 # add `file' is now being backed up (and is possibly
1125 # being reentered into the backups system). `cur'
1126 # is created and RCS files, if necessary, are
1129 # update `file' has changed and needs to be backed up.
1130 # If `cur' exists, it is copied to to `back' or
1131 # checked into RCS (if the repository file is old),
1132 # and then `file' is copied to `cur'. Another RCS
1133 # check in done here if RCS is being used.
1135 # remove `file' is no longer being tracked by the backups
1136 # system. If RCS is not being used, `cur' is moved
1137 # to `back', otherwise an empty file is checked in,
1138 # and then `cur' is removed.
1148 if checkyesno backup_uses_rcs; then
1149 _msg0="backup archive"
1152 # ensure that history file is not locked
1153 if [ -f $_cur,v ]; then
1154 rcs -q -u -U -M $_cur
1157 # ensure after switching to rcs that the
1158 # current backup is not lost
1159 if [ -f $_cur ]; then
1160 # no archive, or current newer than archive
1161 if [ ! -f $_cur,v -o $_cur -nt $_cur,v ]; then
1162 ci -q -f -u -t-"$_msg0" -m"$_msg1" $_cur
1170 cp -p $_cpfile $_cur
1171 ci -q -f -u -t-"$_msg0" -m"$_msg1" $_cur
1174 chown root:wheel $_cur $_cur,v
1178 ci -q -f -u -t-"$_msg0" -m"$_msg1" $_cur
1180 chown root:wheel $_cur $_cur,v
1187 if [ -f $_cur ]; then
1190 cp -p $_cpfile $_cur
1191 chown root:wheel $_cur