svn commit: r219578 - head/etc

Jilles Tjoelker jilles at stack.nl
Sat Mar 12 23:08:31 UTC 2011


On Sat, Mar 12, 2011 at 09:13:08PM +0000, Doug Barton wrote:
> Author: dougb
> Date: Sat Mar 12 21:13:08 2011
> New Revision: 219578
> URL: http://svn.freebsd.org/changeset/base/219578

> Log:
>   Use the allexport option in load_rc_config() in order to avoid having
>   to repeatedly read the conf files. Depending on what is enabled the
>   files are being read anywhere from 15, 30, or more times currently.
>   By loading the values in the environment this is reduced to 1, with
>   perhaps a couple more, again depending on what is enabled.

I wonder if it is a good idea to pollute the environment of many daemons
with this. Although sshd and cron clean it up, there is at least one
daemon that passes the environment on. One of those is devd. While that
saves four /etc/rc.conf reads on my minimalistic 9-current VM, it
implies that devd must be restarted to pick up changes to /etc/rc.conf.
That seems a POLA violation.

With the old code, my VM reads rc.conf nine times at boot. One of them
is the initial load, four of them are via devd and the other four are
because rc.d scripts call each other via execve(2) instead of via the
run_rc_script function. The latter four can be avoided but the other
five seem unavoidable.

I found this by adding the following line to /etc/rc.conf:
echo "rc.conf is being read at $(date) by $(ps -p $$ -o pid= -o ppid= -o args=)" >/dev/console

(The new code reads rc.conf once.)

>   The speed-up for boot and shutdown is negligible when rc.conf is
>   on local disk, noticable when accessing files over NFS, and dramatic
>   when pulling rc.conf values from a database.

>   This change also includes a minor optimization to the conditional
>   for $_rc_conf_loaded.

I don't know if we ever supported 'set -u' in rc.d scripts, but this
definitely breaks it. To fix this, test "${_rc_conf_loaded-}" instead of
"$_rc_conf_loaded"

> Modified:
>   head/etc/rc.subr
> 
> Modified: head/etc/rc.subr
> ==============================================================================
> --- head/etc/rc.subr	Sat Mar 12 20:36:52 2011	(r219577)
> +++ head/etc/rc.subr	Sat Mar 12 21:13:08 2011	(r219578)
> @@ -998,9 +998,8 @@ load_rc_config()
>  		err 3 'USAGE: load_rc_config name'
>  	fi
>  
> -	if ${_rc_conf_loaded:-false}; then
> -		:
> -	else
> +	if [ -z "$_rc_conf_loaded" ]; then
> +		set -o allexport
>  		if [ -r /etc/defaults/rc.conf ]; then
>  			debug "Sourcing /etc/defaults/rc.conf"
>  			. /etc/defaults/rc.conf
> @@ -1010,6 +1009,7 @@ load_rc_config()
>  			. /etc/rc.conf
>  		fi
>  		_rc_conf_loaded=true
> +		set +o allexport
>  	fi
>  	if [ -f /etc/rc.conf.d/"$_name" ]; then
>  		debug "Sourcing /etc/rc.conf.d/${_name}"

-- 
Jilles Tjoelker


More information about the svn-src-all mailing list