Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 May 2011 16:25:14 -0700
From:      Garrett Cooper <yanegomi@gmail.com>
To:        Jilles Tjoelker <jilles@stack.nl>
Cc:        freebsd-rc@freebsd.org
Subject:   Re: [RFC][Change-Request] Create usefulness in rc.subr etc/rc.conf.d/*.conf namespace.
Message-ID:  <BANLkTimWDY8gGKFXQes7StAmvnDuxetdgQ@mail.gmail.com>
In-Reply-To: <20110508221129.GA89657@stack.nl>
References:  <20110508191336.GC3527@DataIX.net> <C7EC90A2-936C-44E1-BC5E-E249399AF9AB@gmail.com> <20110508202636.GF3527@DataIX.net> <D1670EA4-437A-4D79-A5FC-8EE4D05466BA@gmail.com> <20110508221129.GA89657@stack.nl>

next in thread | previous in thread | raw e-mail | index | archive | help

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BANLkTimWDY8gGKFXQes7StAmvnDuxetdgQ>