Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Apr 2000 16:51:24 +0200
From:      Neil Blakey-Milner <nbm@mithrandr.moria.org>
To:        Doug Barton <Doug@gorean.org>
Cc:        freebsd-hackers@freebsd.org, adrian@creative.net.au
Subject:   Re: Safe sourcing of rc files
Message-ID:  <20000419165123.A59794@mithrandr.moria.org>
In-Reply-To: <38F17E7A.5892318A@gorean.org>; from Doug@gorean.org on Mon, Apr 10, 2000 at 12:10:50AM -0700
References:  <38F17E7A.5892318A@gorean.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon 2000-04-10 (00:10), Doug Barton wrote:
> +if [ -z "${sourcercs_defined}" ]; then
> +        sourcercs_defined=yes
> +        sourcercs ( ) {
> +                local sourced_files
> +                for i in ${rc_conf_files}; do
> +                        case "${sourced_files}" in
> +                        *:$i:*)
> +                                ;;
> +                        *)
> +                                sourced_files="${sourced_files}:$i:"
> +                                if [ -r $i ]; then
> +                                        . $i
> +                                fi
> +                                ;;
> +                        esac
> +                done
> +        }
> +fi

I have another idea:  We make a sh script named "rcsource" or whatever,
which we source when we want to have the rc environment, stealing your
code maliciously:

/--
sourcercs_sourced_files=
sourcercs ( ) {
        local rc_conf_files
        for i in $*; do
                case "${sourcercs_sourced_files}" in
                *:$i:*)
                        ;;
                *)
                        sourcercs_sourced_files="${sourcercs_sourced_files}:$i:"
                        echo $i
                        if [ -r $i ]; then
                                . $i
                                sourcercs ${rc_conf_files}
                        fi
                        ;;
                esac
        done
}
sourcercs /etc/defaults/rc.conf
\--

Anyway, this'll do something I've been considering missing - the ability
to set more rc_conf_files in /etc/rc.conf and friends.  It also means a
total lack of sh-script in /etc/defaults/rc.conf and /etc/rc.conf, which
means that we can start developing something in C that can read those
files (libconf, Daniel?).

Basically, it localizes rc_conf_files so that you don't lose any you've
specified before.  So, in /etc/defaults/rc.conf, it sets rc_conf_files
to "/etc/rc.conf /etc/rc.conf.local", and when it runs /etc/rc.conf,
rc_conf_files changes to "/etc/foo.conf", and that'll be read.  After
it's finished, it pops up two spaces, and goes on to /etc/rc.conf.local.

A file will only ever be sourced once.

One possible extension may be a specifier of a preprocessor for a file:

preprocessor__etc_defaults_rc.conf='cpp' will be checked if sourcercs is
run on /etc/defaults/rc.conf, and it will be passed through cpp before
trying to understand it.  This should be extensible enough to avoid the
need of sh-script to get a value for a variable.

Any more ideas?

Neil
-- 
Neil Blakey-Milner
Hacker In Chief, Sunesi Clinical Systems
nbm@mithrandr.moria.org


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




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