Deleted Added
full compact
rc.subr (193118) rc.subr (197144)
1# $NetBSD: rc.subr,v 1.67 2006/10/07 11:25:15 elad Exp $
1# $NetBSD: rc.subr,v 1.67 2006/10/07 11:25:15 elad Exp $
2# $FreeBSD: head/etc/rc.subr 193118 2009-05-30 21:41:54Z dougb $
2# $FreeBSD: head/etc/rc.subr 197144 2009-09-12 22:19:48Z hrs $
3#
4# Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# This code is derived from software contributed to The NetBSD Foundation
8# by Luke Mewburn.
9#
10# Redistribution and use in source and binary forms, with or without

--- 56 unchanged lines hidden (view full) ---

67 SYSCTL_W="${SYSCTL} -w"
68 ;;
69esac
70
71#
72# functions
73# ---------
74
3#
4# Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# This code is derived from software contributed to The NetBSD Foundation
8# by Luke Mewburn.
9#
10# Redistribution and use in source and binary forms, with or without

--- 56 unchanged lines hidden (view full) ---

67 SYSCTL_W="${SYSCTL} -w"
68 ;;
69esac
70
71#
72# functions
73# ---------
74
75# set_rcvar [var] [defval] [desc]
75#
76#
76# set_rcvar base_var
77# Set the variable name enabling a specific service.
78# FreeBSD uses ${service}_enable, while NetBSD uses
79# just the name of the service. For example:
80# FreeBSD: sendmail_enable="YES"
81# NetBSD : sendmail="YES"
82# $1 - if $name is not the base to work of off, specify
83# a different one
77# Echo or define a rc.conf(5) variable name. Global variable
78# $rcvars is used.
84#
79#
80# If no argument is specified, echo "${name}_enable".
81#
82# If only a var is specified, echo "${var}_enable".
83#
84# If var and defval are specified, the ${var} is defined as
85# rc.conf(5) variable and the default value is ${defvar}. An
86# optional argument $desc can also be specified to add a
87# description for that.
88#
85set_rcvar()
86{
89set_rcvar()
90{
87 if [ -z "$1" ]; then
88 base_var=${name}
89 else
90 base_var="$1"
91 fi
92
93 case ${OSTYPE} in
94 FreeBSD)
95 echo ${base_var}_enable
91 case $# in
92 0)
93 echo ${name}_enable
96 ;;
94 ;;
97 NetBSD)
98 echo ${base_var}
95 1)
96 echo ${1}_enable
99 ;;
100 *)
97 ;;
98 *)
101 echo 'XXX'
99 debug "rcvar_define: \$$1=$2 is added" \
100 " as a rc.conf(5) variable."
101
102 local _var
103 _var=$1
104 rcvars="${rcvars# } $_var"
105 eval ${_var}_defval=\"$2\"
106 shift 2
107 # encode multiple lines of _desc
108 for l in "$@"; do
109 eval ${_var}_desc=\"\${${_var}_desc#^^}^^$l\"
110 done
111 eval ${_var}_desc=\"\${${_var}_desc#^^}\"
102 ;;
103 esac
104}
105
112 ;;
113 esac
114}
115
116# set_rcvar_obsolete oldvar [newvar] [msg]
117# Define obsolete variable.
118# Global variable $rcvars_obsolete is used.
106#
119#
120set_rcvar_obsolete()
121{
122 local _var
123 _var=$1
124 debug "rcvar_obsolete: \$$1(old) -> \$$2(new) is defined"
125
126 rcvars_obsolete="${rcvars_obsolete# } $1"
127 eval ${1}_newvar=\"$2\"
128 shift 2
129 eval ${_var}_obsolete_msg=\"$*\"
130}
131
132#
107# force_depend script
108# Force a service to start. Intended for use by services
109# to resolve dependency issues. It is assumed the caller
110# has check to make sure this call is necessary
111# $1 - filename of script, in /etc/rc.d, to run
112#
113force_depend()
114{

--- 281 unchanged lines hidden (view full) ---

396# Not needed if ${rc_arg}_cmd is set for
397# each keyword.
398#
399# command_args n Optional args/shell directives for command.
400#
401# command_interpreter n If not empty, command is interpreted, so
402# call check_{pidfile,process}() appropriately.
403#
133# force_depend script
134# Force a service to start. Intended for use by services
135# to resolve dependency issues. It is assumed the caller
136# has check to make sure this call is necessary
137# $1 - filename of script, in /etc/rc.d, to run
138#
139force_depend()
140{

--- 281 unchanged lines hidden (view full) ---

422# Not needed if ${rc_arg}_cmd is set for
423# each keyword.
424#
425# command_args n Optional args/shell directives for command.
426#
427# command_interpreter n If not empty, command is interpreted, so
428# call check_{pidfile,process}() appropriately.
429#
430# desc n Description of script.
431#
404# extra_commands n List of extra commands supported.
405#
406# pidfile n If set, use check_pidfile $pidfile $command,
407# otherwise use check_process $command.
408# In either case, only check if $command is set.
409#
410# procname n Process name to check for instead of $command.
411#

--- 157 unchanged lines hidden (view full) ---

569 quiet*) # "quiet" prefix; omit some messages
570 _rc_prefix=quiet
571 rc_arg=${rc_arg#${_rc_prefix}}
572 rc_quiet=yes
573 ;;
574 esac
575
576 eval _override_command=\$${name}_program
432# extra_commands n List of extra commands supported.
433#
434# pidfile n If set, use check_pidfile $pidfile $command,
435# otherwise use check_process $command.
436# In either case, only check if $command is set.
437#
438# procname n Process name to check for instead of $command.
439#

--- 157 unchanged lines hidden (view full) ---

597 quiet*) # "quiet" prefix; omit some messages
598 _rc_prefix=quiet
599 rc_arg=${rc_arg#${_rc_prefix}}
600 rc_quiet=yes
601 ;;
602 esac
603
604 eval _override_command=\$${name}_program
577 command=${command:+${_override_command:-$command}}
605 command=${command:-${_override_command}}
578
579 _keywords="start stop restart rcvar $extra_commands"
580 rc_pid=
581 _pidcmd=
582 _procname=${procname:-${command}}
583
584 # setup pid check command
585 if [ -n "$_procname" ]; then

--- 187 unchanged lines hidden (view full) ---

773 _run_rc_precmd || return 1
774 if [ -n "$rc_pid" ]; then
775 wait_for_pids $rc_pid
776 fi
777 _run_rc_postcmd
778 ;;
779
780 rcvar)
606
607 _keywords="start stop restart rcvar $extra_commands"
608 rc_pid=
609 _pidcmd=
610 _procname=${procname:-${command}}
611
612 # setup pid check command
613 if [ -n "$_procname" ]; then

--- 187 unchanged lines hidden (view full) ---

801 _run_rc_precmd || return 1
802 if [ -n "$rc_pid" ]; then
803 wait_for_pids $rc_pid
804 fi
805 _run_rc_postcmd
806 ;;
807
808 rcvar)
781 echo "# $name"
782 if [ -n "$rcvar" ]; then
783 if checkyesno ${rcvar}; then
784 echo "${rcvar}=YES"
785 else
786 echo "${rcvar}=NO"
787 fi
809 echo -n "# $name"
810 if [ -n "$desc" ]; then
811 echo " : $desc"
812 else
813 echo ""
788 fi
814 fi
815 echo "#"
816 # Get unique vars in $rcvar $rcvars
817 for _v in $rcvar $rcvars; do
818 case $v in
819 $_v\ *|\ *$_v|*\ $_v\ *) ;;
820 *) v="${v# } $_v" ;;
821 esac
822 done
823
824 # Display variables.
825 for _v in $v; do
826 if [ -z "$_v" ]; then
827 continue
828 fi
829
830 eval _desc=\$${_v}_desc
831 eval _defval=\$${_v}_defval
832 _h="-"
833
834 eval echo \"$_v=\\\"\$$_v\\\"\"
835 # decode multiple lines of _desc
836 while [ -n "$_desc" ]; do
837 case $_desc in
838 *^^*)
839 echo "# $_h ${_desc%%^^*}"
840 _desc=${_desc#*^^}
841 _h=" "
842 ;;
843 *)
844 echo "# $_h ${_desc}"
845 break
846 ;;
847 esac
848 done
849 echo "# (default: \"$_defval\")"
850 done
851 echo ""
789 ;;
790
791 *)
792 rc_usage $_keywords
793 ;;
794
795 esac
796 return $_return

--- 94 unchanged lines hidden (view full) ---

891 _file=$1
892 _arg=$2
893 if [ -z "$_file" -o -z "$_arg" ]; then
894 err 3 'USAGE: run_rc_script file arg'
895 fi
896
897 unset name command command_args command_interpreter \
898 extra_commands pidfile procname \
852 ;;
853
854 *)
855 rc_usage $_keywords
856 ;;
857
858 esac
859 return $_return

--- 94 unchanged lines hidden (view full) ---

954 _file=$1
955 _arg=$2
956 if [ -z "$_file" -o -z "$_arg" ]; then
957 err 3 'USAGE: run_rc_script file arg'
958 fi
959
960 unset name command command_args command_interpreter \
961 extra_commands pidfile procname \
899 rcvar required_dirs required_files required_vars
962 rcvar rcvars rcvars_obsolete required_dirs required_files \
963 required_vars
900 eval unset ${_arg}_cmd ${_arg}_precmd ${_arg}_postcmd
901
902 case "$_file" in
903 /etc/rc.d/*.sh) # no longer allowed in the base
904 warn "Ignoring old-style startup script $_file"
905 ;;
906 *[~#]|*.OLD|*.bak|*.orig|*,v) # scratch file; skip
907 warn "Ignoring scratch file $_file"

--- 14 unchanged lines hidden (view full) ---

922}
923
924#
925# load_rc_config name
926# Source in the configuration file for a given name.
927#
928load_rc_config()
929{
964 eval unset ${_arg}_cmd ${_arg}_precmd ${_arg}_postcmd
965
966 case "$_file" in
967 /etc/rc.d/*.sh) # no longer allowed in the base
968 warn "Ignoring old-style startup script $_file"
969 ;;
970 *[~#]|*.OLD|*.bak|*.orig|*,v) # scratch file; skip
971 warn "Ignoring scratch file $_file"

--- 14 unchanged lines hidden (view full) ---

986}
987
988#
989# load_rc_config name
990# Source in the configuration file for a given name.
991#
992load_rc_config()
993{
994 local _name _var _defval _v _msg _new
930 _name=$1
931 if [ -z "$_name" ]; then
932 err 3 'USAGE: load_rc_config name'
933 fi
934
935 if ${_rc_conf_loaded:-false}; then
936 :
937 else

--- 10 unchanged lines hidden (view full) ---

948 if [ -f /etc/rc.conf.d/"$_name" ]; then
949 debug "Sourcing /etc/rc.conf.d/${_name}"
950 . /etc/rc.conf.d/"$_name"
951 fi
952
953 # Old variable names support
954 #
955 [ -n "$enable_quotas" ] && quota_enable="$enable_quotas"
995 _name=$1
996 if [ -z "$_name" ]; then
997 err 3 'USAGE: load_rc_config name'
998 fi
999
1000 if ${_rc_conf_loaded:-false}; then
1001 :
1002 else

--- 10 unchanged lines hidden (view full) ---

1013 if [ -f /etc/rc.conf.d/"$_name" ]; then
1014 debug "Sourcing /etc/rc.conf.d/${_name}"
1015 . /etc/rc.conf.d/"$_name"
1016 fi
1017
1018 # Old variable names support
1019 #
1020 [ -n "$enable_quotas" ] && quota_enable="$enable_quotas"
1021
1022 # Set defaults if defined.
1023 for _var in $rcvar $rcvars; do
1024 _defval=`eval echo "\\\$${_var}_defval"`
1025 if [ -n "$_defval" ]; then
1026 eval : \${$_var:=\$${_var}_defval}
1027 fi
1028 done
1029
1030 # check obsolete rc.conf variables
1031 for _var in $rcvars_obsolete; do
1032 _v=`eval echo \\$$_var`
1033 _msg=`eval echo \\$${_var}_obsolete_msg`
1034 _new=`eval echo \\$${_var}_newvar`
1035 case $_v in
1036 "")
1037 ;;
1038 *)
1039 if [ -z "$_new" ]; then
1040 _msg="Ignored."
1041 else
1042 eval $_new=\"\$$_var\"
1043 if [ -z "$_msg" ]; then
1044 _msg="Use \$$_new instead."
1045 fi
1046 fi
1047 warn "\$$_var is obsolete. $_msg"
1048 ;;
1049 esac
1050 done
956}
957
958#
959# load_rc_config_var name var
960# Read the rc.conf(5) var for name and set in the
961# current shell, using load_rc_config in a subshell to prevent
962# unwanted side effects from other variable assignments.
963#

--- 626 unchanged lines hidden (view full) ---

1590 ;;
1591 esac
1592
1593 return 0
1594}
1595
1596fi
1597
1051}
1052
1053#
1054# load_rc_config_var name var
1055# Read the rc.conf(5) var for name and set in the
1056# current shell, using load_rc_config in a subshell to prevent
1057# unwanted side effects from other variable assignments.
1058#

--- 626 unchanged lines hidden (view full) ---

1685 ;;
1686 esac
1687
1688 return 0
1689}
1690
1691fi
1692
1693# _echoonce var msg mode
1694# mode=0: Echo $msg if ${$var} is empty.
1695# After doing echo, a string is set to ${$var}.
1696#
1697# mode=1: Echo $msg if ${$var} is a string with non-zero length.
1698#
1699_echoonce()
1700{
1701 local _var _msg _mode
1702 _var=`eval echo \\$$1`
1703 _msg=$2
1704 _mode=$3
1705
1706 case $_mode in
1707 1) [ -n "$_var" ] && echo "$_msg" ;;
1708 *) [ -z "$_var" ] && echo -n "$_msg" && eval "$1=finished" ;;
1709 esac
1710}
1711
1598_rc_subr_loaded=:
1712_rc_subr_loaded=: