[RFC][Change-Request] Create usefulness in rc.subr etc/rc.conf.d/*.conf namespace.

Devin Teske dteske at vicor.com
Mon May 9 00:57:10 UTC 2011


On May 8, 2011, at 5:23 PM, Jason Hellenthal wrote:

> 
> Devin,
> 
> On Sun, May 08, 2011 at 03:52:06PM -0700, Devin Teske wrote:
>> 
>> I second Jilles all-builtin solution using `for' globbing (no forking external processes or sub-shells).
>> 
>> Slight modification for brevity:
>> 
>> 	for _modular_conf in /etc/rc.conf.d/*.conf; do
>> 		[ -f "$_modular_conf" -a -x "$_modular_conf" ] || continue
>> 		debug "Sourcing $_modular_conf"
>> 		. "$_modular_conf"
>> 	done
>> 
>> Though I still think it ought to be:
>> 
>> 	for _modular_conf in /etc/rc.conf.d/*.conf; do
>> 		[ -f "$_modular_conf" ] || continue
>> 		debug "Sourcing $_modular_conf"
>> 		. "$_modular_conf"
>> 	done
>> 
> 
> Keeping with the examples of the rest of the style of rc.subr and plenty 
> of other shell scripts here. This would be a distortion of the 
> functionality that the original loop is doing and should be avoided.
> 

I've picked up this tid-bit over the years:

1. Since a conditional block causes all code within to be indented...
2. if you have a condition which can cause a continuance within a looping bock...
3. utilizing said conditional early-on can prevent unnecessary indentation in the following lines.

It's kind of moot for such a small example, but if you get to nesting 300+ lines at multiple levels of nesting then it's worth re-evaluating the use of "early continuances".

Here's the basic idea...

	for item in list; do
		: condition to continue
		: what the loop does
	done

opposed to:

	for item in list; do
		if : condition to not continue; then
			: what the loop does
		fi
	done

How about this half-and-half approach (actual code):

	for _modular_conf in /etc/rc.conf.d/*.conf; do
		if [ ! -f "$_modular_conf" ]; then
			continue
		fi
		debug "Sourcing $_modular_conf"
		. "$_modular_conf"
	done

Of course, one's interpretation of the above syntax is conditional on memorizing that "!" is pronounced "not" (just as my previous syntax hinges on memorizing that "||" is pronounced "or"/"else" -- allowing either syntax to be read/interpreted with ease).

Just thought I'd share my experiences. Not everyone develops the same style(9) for every language.
-- 
Devin

_____________

The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.
_____________


More information about the freebsd-rc mailing list