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

Jilles Tjoelker jilles at stack.nl
Sun May 8 22:11:31 UTC 2011


On Sun, May 08, 2011 at 02:19:17PM -0700, Garrett Cooper wrote:
> >> 	Doing:

> >> find /etc/rc.conf.d/ -type f -name '*.conf' -mindepth 1 -maxdepth 1 -perm +111 | while read _modular_conf; do
> >> 	debug "Sourcing $_modular_conf"
> >> 	. "$_modular_conf"
> >> done

> >> 	might be better. There's some more magic that could ultimately be done to make this more secure/robust using "-print0" | xargs, but it's up to you how you might want to go about solving that problem.
> >> 	Also, I don't know if depending on a .conf file to be executable is necessarily the best course of action.

> > Yeah I see what you are getting at there and I came across thinking the 
> > same thing. Fortunately /etc/rc.conf.d/*.conf is only one level deep 
> > without using find(1).

> Yes, but the above method used avoids simple E2BIG problems. It just
> doesn't properly deal with filenames that break on IFS, etc though
> (that's part of where I was leading, but I said "security" instead.

I would say the opposite. jhell's original loop

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

with a small change
-				. $_modular_conf
+				. "$_modular_conf"

does not have any E2BIG problems, and also no problems with special
characters. This is because the list of pathnames stays within sh; it is
not passed to another program. If there is no matching file, the loop
runs once for /etc/rc.conf.d/*.conf which does not exist and is
therefore not sourced.

Any 'while read...' loop will handle pathnames with newlines
incorrectly, and the simple ones also handle backslashes and certain
whitespace incorrectly. Also, the proposed pipeline does not even work
as the while loop is executed in a subshell, so the assignments in the
sourced files are lost.

This post is not an endorsement of jhell's idea. I am not really
convinced it is useful. For experimenting, the for command can be placed
in /etc/rc.conf.

-- 
Jilles Tjoelker


More information about the freebsd-rc mailing list