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

Garrett Cooper yanegomi at gmail.com
Sun May 8 23:25:15 UTC 2011


On Sun, May 8, 2011 at 3:11 PM, Jilles Tjoelker <jilles at stack.nl> wrote:
> 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.

Hmmm... ok. Didn't realize that. As a bonus point -- is that an
extension of our shell, or is this standard behavior in all shells?

> 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.

Ah drat... I forgot that our shell does subshells with pipelines.
Thanks Jilles for the correction ><..

> 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.

-Garrett


More information about the freebsd-rc mailing list