From owner-freebsd-hackers Wed Apr 19 7:51:54 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from ns1.sunesi.net (ns1.sunesi.net [196.15.192.194]) by hub.freebsd.org (Postfix) with ESMTP id EA59A37B518 for ; Wed, 19 Apr 2000 07:51:48 -0700 (PDT) (envelope-from nbm@sunesi.net) Received: from nbm by ns1.sunesi.net with local (Exim 3.03 #1) id 12hvp6-000Fb3-00; Wed, 19 Apr 2000 16:51:24 +0200 Date: Wed, 19 Apr 2000 16:51:24 +0200 From: Neil Blakey-Milner To: Doug Barton Cc: freebsd-hackers@freebsd.org, adrian@creative.net.au Subject: Re: Safe sourcing of rc files Message-ID: <20000419165123.A59794@mithrandr.moria.org> References: <38F17E7A.5892318A@gorean.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <38F17E7A.5892318A@gorean.org>; from Doug@gorean.org on Mon, Apr 10, 2000 at 12:10:50AM -0700 Organization: Sunesi Clinical Systems X-Operating-System: FreeBSD 3.3-RELEASE i386 X-URL: http://rucus.ru.ac.za/~nbm/ Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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