Date: Mon, 10 Apr 2000 00:10:50 -0700 From: Doug Barton <Doug@gorean.org> To: freebsd-hackers@freebsd.org, adrian@creative.net.au Subject: Safe sourcing of rc files Message-ID: <38F17E7A.5892318A@gorean.org>
next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------244E2C58B24606139E1F0806 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Since the move to /etc/defaults/rc.conf, one of the consistent examples of foot-shooting is the user blindly copying that file to /etc/rc.conf without reading the warning at the end not to do this, or at least to delete the bit at the end that does the recursive sourcing of /etc/rc.conf and /etc/rc.conf.local. After careful experimentation, and a few abortive attempts, I have developed the following technique. The major change is that instead of the files being sourced from the bit of code in /etc/defaults/rc.conf itself, that file defines a function that the other scripts which source /etc/defaults/rc.conf use to do the recursive sort. That function uses a local variable to keep track of which files it has already sourced in order to prevent an infinite loop. The use of the function and the local variable allow the rc.conf* files to be sourced by rc, then sourced again by rc.firewall (for example) and still do the right thing all the way around. I have done extensive testing with a set of scripts that I developed to emulate the /etc/rc*'s. I have also tested it in place, rebooting with various configurations, including and especially the standard bonehead user mode mentioned above. In each case the following patch does the right thing. My testing included scenarios with multiple /etc/rc.conf* files. I believe that the attached patch is ready to be committed. Discussion is welcome. This patch is applicable to PR 17595. Doug -- Excess on occasion is exhilarating. It prevents moderation from acquiring the deadening effect of a habit. -- W. Somerset Maugham --------------244E2C58B24606139E1F0806 Content-Type: text/plain; charset=us-ascii; name="safesourcing.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="safesourcing.diff" Index: netstart =================================================================== RCS file: /usr/ncvs/src/etc/netstart,v retrieving revision 1.54 diff -u -r1.54 netstart --- netstart 1999/08/27 23:23:42 1.54 +++ netstart 2000/04/10 06:12:38 @@ -12,6 +12,7 @@ # If there is a global system configuration file, suck it in. if [ -f /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf + sourcercs elif [ -f /etc/rc.conf ]; then . /etc/rc.conf fi Index: pccard_ether =================================================================== RCS file: /usr/ncvs/src/etc/pccard_ether,v retrieving revision 1.15 diff -u -r1.15 pccard_ether --- pccard_ether 2000/02/11 14:49:42 1.15 +++ pccard_ether 2000/04/10 06:12:51 @@ -11,6 +11,7 @@ # if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf + sourcercs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi Index: rc =================================================================== RCS file: /usr/ncvs/src/etc/rc,v retrieving revision 1.214 diff -u -r1.214 rc --- rc 2000/03/27 16:36:25 1.214 +++ rc 2000/04/10 06:13:10 @@ -38,6 +38,7 @@ # if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf + sourcercs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi Index: rc.devfs =================================================================== RCS file: /usr/ncvs/src/etc/rc.devfs,v retrieving revision 1.7 diff -u -r1.7 rc.devfs --- rc.devfs 1999/10/12 19:23:51 1.7 +++ rc.devfs 2000/04/10 06:13:23 @@ -5,6 +5,7 @@ # if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf + sourcercs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi Index: rc.diskless2 =================================================================== RCS file: /usr/ncvs/src/etc/rc.diskless2,v retrieving revision 1.5 diff -u -r1.5 rc.diskless2 --- rc.diskless2 2000/01/06 18:17:38 1.5 +++ rc.diskless2 2000/04/10 06:13:37 @@ -7,6 +7,7 @@ # if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf + sourcercs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi Index: rc.firewall =================================================================== RCS file: /usr/ncvs/src/etc/rc.firewall,v retrieving revision 1.30 diff -u -r1.30 rc.firewall --- rc.firewall 2000/02/06 19:24:37 1.30 +++ rc.firewall 2000/04/10 06:14:07 @@ -5,6 +5,7 @@ # Suck in the configuration variables. if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf + sourcercs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi Index: defaults/rc.conf =================================================================== RCS file: /usr/ncvs/src/etc/defaults/rc.conf,v retrieving revision 1.58 diff -u -r1.58 rc.conf --- defaults/rc.conf 2000/04/03 19:24:19 1.58 +++ defaults/rc.conf 2000/04/10 06:43:12 @@ -294,9 +294,22 @@ # # -for i in ${rc_conf_files}; do - if [ -f $i ]; then - . $i - fi -done +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 --------------244E2C58B24606139E1F0806-- 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?38F17E7A.5892318A>