Index: src/etc/rc.subr =================================================================== RCS file: /home/ncvs/src/etc/rc.subr,v retrieving revision 1.51 diff -u -r1.51 rc.subr --- src/etc/rc.subr 4 Apr 2006 10:52:15 -0000 1.51 +++ src/etc/rc.subr 10 Apr 2006 13:01:51 -0000 @@ -362,6 +362,10 @@ # rcvar n This is checked with checkyesno to determine # if the action should be run. # +# ${name}_program n Full path to command. +# Meant to be used in /etc/rc.conf to override +# ${command}. +# # ${name}_chroot n Directory to chroot to before running ${command} # Requires /usr to be mounted. # @@ -498,9 +502,6 @@ ;; esac - eval _override_command=\$${name}_program - command=${command:+${_override_command:-$command}} - _keywords="start stop restart rcvar $extra_commands" rc_pid= _pidcmd= @@ -857,14 +858,16 @@ } # -# load_rc_config command -# Source in the configuration file for a given command. +# load_rc_config name +# Source in the configuration file for a given name. # load_rc_config() { - _command=$1 - if [ -z "$_command" ]; then - err 3 'USAGE: load_rc_config command' + local _tmp + + _name=$1 + if [ -z "$_name" ]; then + err 3 'USAGE: load_rc_config name' fi if ${_rc_conf_loaded:-false}; then @@ -880,9 +883,35 @@ fi _rc_conf_loaded=true fi - if [ -f /etc/rc.conf.d/"$_command" ]; then - debug "Sourcing /etc/rc.conf.d/${_command}" - . /etc/rc.conf.d/"$_command" + + eval _override_command=\$${name}_program + command=${command:+${_override_command:-$command}} + + if [ -z "${command}" ]; then + _tmp=`/bin/realpath $0` + prefix=${_tmp%/etc/rc.d/*}/ + else + prefix=${command%/*bin/*}/ + fi + if [ "${prefix}" = "/" -o "${prefix}" = "/usr/" ] ; then + etcdir="/etc" + else + etcdir="${prefix}etc" + fi + + # XXX - Deprecated + if [ -f /etc/rc.conf.d/${_name} -a ${etcdir} != "/etc" ]; then + debug "Sourcing /etc/rc.conf.d/${_name}" + warn "Warning: /etc/rc.conf.d/${_name} is deprecated, please use ${etcdir}/rc.conf.d/${_name} instead." + if [ -f ${etcdir}/rc.conf.d/${_name} ] + warn "Warning: Both /etc/rc.conf.d/${_name} and ${etcdir}/rc.conf.d/${_name} exist." + fi + . /etc/rc.conf.d/${_name} + fi + + if [ -f ${etcdir}/rc.conf.d/${_name} ]; then + debug "Sourcing ${etcdir}/rc.conf.d/${_name}" + . ${etcdir}/rc.conf.d/${_name} fi # XXX - Deprecated variable name support @@ -903,15 +932,15 @@ } # -# load_rc_config_var cmd var -# Read the rc.conf(5) var for cmd and set in the +# load_rc_config_var name var +# Read the rc.conf(5) var for name and set in the # current shell, using load_rc_config in a subshell to prevent # unwanted side effects from other variable assignments. # load_rc_config_var() { if [ $# -ne 2 ]; then - err 3 'USAGE: load_rc_config_var cmd var' + err 3 'USAGE: load_rc_config_var name var' fi eval $(eval '( load_rc_config '$1' >/dev/null; Index: src/etc/rc.d/sshd =================================================================== RCS file: /home/ncvs/src/etc/rc.d/sshd,v retrieving revision 1.9 diff -u -r1.9 sshd --- src/etc/rc.d/sshd 23 Oct 2005 14:06:53 -0000 1.9 +++ src/etc/rc.d/sshd 10 Apr 2006 13:01:51 -0000 @@ -19,6 +19,8 @@ timeout=300 +load_rc_config $name + user_reseed() { ( @@ -47,47 +49,46 @@ umask 022 # Can't do anything if ssh is not installed - [ -x /usr/bin/ssh-keygen ] || { - warn "/usr/bin/ssh-keygen does not exist." + [ -x ${prefix}/bin/ssh-keygen ] || { + warn "${prefix}/bin/ssh-keygen does not exist." return 1 } - if [ -f /etc/ssh/ssh_host_key ]; then + if [ -f ${etcdir}/ssh/ssh_host_key ]; then echo "You already have an RSA host key" \ - "in /etc/ssh/ssh_host_key" + "in ${etcdir}/ssh/ssh_host_key" echo "Skipping protocol version 1 RSA Key Generation" else - /usr/bin/ssh-keygen -t rsa1 -b 1024 \ - -f /etc/ssh/ssh_host_key -N '' + ${prefix}/bin/ssh-keygen -t rsa1 -b 1024 \ + -f ${etcdir}/ssh/ssh_host_key -N '' fi - if [ -f /etc/ssh/ssh_host_dsa_key ]; then + if [ -f ${etcdir}/ssh/ssh_host_dsa_key ]; then echo "You already have a DSA host key" \ - "in /etc/ssh/ssh_host_dsa_key" + "in ${etcdir}/ssh/ssh_host_dsa_key" echo "Skipping protocol version 2 DSA Key Generation" else - /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' + ${prefix}/bin/ssh-keygen -t dsa -f ${etcdir}/ssh/ssh_host_dsa_key -N '' fi - if [ -f /etc/ssh/ssh_host_rsa_key ]; then + if [ -f ${etcdir}/ssh/ssh_host_rsa_key ]; then echo "You already have a RSA host key" \ - "in /etc/ssh/ssh_host_rsa_key" + "in ${etcdir}/ssh/ssh_host_rsa_key" echo "Skipping protocol version 2 RSA Key Generation" else - /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' + ${prefix}/bin/ssh-keygen -t rsa -f ${etcdir}/ssh/ssh_host_rsa_key -N '' fi ) } sshd_precmd() { - if [ ! -f /etc/ssh/ssh_host_key -o \ - ! -f /etc/ssh/ssh_host_dsa_key -o \ - ! -f /etc/ssh/ssh_host_rsa_key ]; then + if [ ! -f ${etcdir}/ssh/ssh_host_key -o \ + ! -f ${etcdir}/ssh/ssh_host_dsa_key -o \ + ! -f ${etcdir}/ssh/ssh_host_rsa_key ]; then user_reseed run_rc_command keygen fi } -load_rc_config $name run_rc_command "$1" Index: src/share/man/man8/rc.subr.8 =================================================================== RCS file: /home/ncvs/src/share/man/man8/rc.subr.8,v retrieving revision 1.11 diff -u -r1.11 rc.subr.8 --- src/share/man/man8/rc.subr.8 4 Apr 2006 10:52:15 -0000 1.11 +++ src/share/man/man8/rc.subr.8 10 Apr 2006 13:01:51 -0000 @@ -36,7 +36,7 @@ .\" .\" $FreeBSD: src/share/man/man8/rc.subr.8,v 1.11 2006/04/04 10:52:15 flz Exp $ .\" -.Dd April 4, 2006 +.Dd April 10, 2006 .Dt RC.SUBR 8 .Os .Sh NAME @@ -312,28 +312,52 @@ .Xr rc.conf 5 variable .Va rc_info . -.It Ic load_rc_config Ar command +.It Ic load_rc_config Ar name Source in the configuration files for -.Ar command . +.Ar name . First, +.Pa /etc/defaults/rc.conf +and .Pa /etc/rc.conf -is sourced if it has not yet been read in. +are sourced if they have not yet been read in. Then, -.Pa /etc/rc.conf.d/ Ns Ar command -is sourced if it is an existing file. +.Va etcdir +variable is set to +.Pa /etc +if +.Va command Ap s +prefix (or +.Va ${name} Ns Va _program Ap s +if it is defined) is +.Pa / +or +.Pa /usr , +otherwise +.Va etcdir +is set to +.Pa ${prefix} Ns Pa /etc . +.Pa /etc/rc.conf.d/ Ns Va ${name} +is sourced if the file exists (but it is deprecated if +.Va etcdir +is different than +.Pa /etc ) +and then +.Va ${etcdir} Ns Pa /rc.conf.d/ Ns Va ${name} +is sourced if the file exists. +will not be sourced anymore (. The latter may also contain other variable assignments to override .Ic run_rc_command arguments defined by the calling script, to provide an easy mechanism for an administrator to override the behaviour of a given .Xr rc.d 8 script without requiring the editing of that script. -.It Ic load_rc_config_var Ar command Ar var +.It Ic load_rc_config_var Ar name Ar var Read the .Xr rc.conf 5 variable .Ar var for -.Ar command +.Ar name and set in the current shell, using .Ic load_rc_config in a sub-shell to prevent unwanted side effects from other variable