From f66e7afa2807fbc9d43ce69f67eac43806530e8e Mon Sep 17 00:00:00 2001 From: Sheldon Hearn Date: Thu, 27 Apr 2000 08:43:49 +0000 Subject: [PATCH] Add to defaults/rc.conf a new function source_rc_confs which rc scripts may use to source safely overrides in ${rc_conf_files} files. This protects users who insist on the bad practice of copying /etc/defaults/rc.conf to /etc/rc.conf from a recursive loop that exhausts available file descriptors. Several people have expressed interest in breaking this function out into its own shell script. Anyone who wants to embark on such an undertaking would do well to study the attributed PR. PR: 17595 Reported by: adrian Submitted by: Doug Barton --- etc/defaults/rc.conf | 35 +++++++++++++++++++++++------------ etc/netstart | 1 + etc/pccard_ether | 1 + etc/rc | 4 ++++ etc/rc.d/diskless | 1 + etc/rc.d/resolv | 1 + etc/rc.d/tmp | 1 + etc/rc.d/var | 1 + etc/rc.devfs | 1 + etc/rc.diskless2 | 1 + etc/rc.firewall | 1 + 11 files changed, 36 insertions(+), 12 deletions(-) diff --git a/etc/defaults/rc.conf b/etc/defaults/rc.conf index dd8a03b990f7..9ce5d1d283af 100644 --- a/etc/defaults/rc.conf +++ b/etc/defaults/rc.conf @@ -7,10 +7,9 @@ # instead and you will be able to update these defaults later without # spamming your local configuration information. # -# A common mistake is to copy the contents of this file into one of the -# ${rc_conf_files} files (e.g. /etc/rc.conf). That does not work, because -# this file ends up recursing on itself. The ${rc_conf_files} files should -# only contain values which override values set in this file. +# The ${rc_conf_files} files should only contain values which override +# values set in this file. This eases the upgrade path when defaults +# are changed and new features are added. # # All arguments must be in double or single quotes. # @@ -289,14 +288,26 @@ update_motd="YES" # update version info in /etc/motd (or NO) start_vinum="" # set to YES to start vinum ############################################################## -### Allow local configuration override at the very end here ## +### Define source_rc_confs, the mechanism used by /etc/rc.* ## +### scripts to source rc_conf_files overrides safely. ## ############################################################## -# -# -for i in ${rc_conf_files}; do - if [ -f $i ]; then - . $i - fi -done +if [ -z "${source_rc_confs_defined}" ]; then + source_rc_confs_defined=yes + source_rc_confs ( ) { + local i 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 diff --git a/etc/netstart b/etc/netstart index 21e67edc9546..041f1fe8646c 100755 --- a/etc/netstart +++ b/etc/netstart @@ -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 + source_rc_confs elif [ -f /etc/rc.conf ]; then . /etc/rc.conf fi diff --git a/etc/pccard_ether b/etc/pccard_ether index dafbc2370e81..f725d611f36e 100755 --- a/etc/pccard_ether +++ b/etc/pccard_ether @@ -11,6 +11,7 @@ # if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf + source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi diff --git a/etc/rc b/etc/rc index b9dbfd8aec86..4e80185ee7b0 100644 --- a/etc/rc +++ b/etc/rc @@ -38,6 +38,7 @@ fi # if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf + source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi @@ -500,6 +501,9 @@ fi # ---- rc.local ---- # if [ -r /etc/defaults/rc.conf ]; then # . /etc/defaults/rc.conf +# source_rc_confs +# elif [ -r /etc/rc.conf ]; then +# . /etc/rc.conf # fi # # ... additional startup conditionals ... diff --git a/etc/rc.d/diskless b/etc/rc.d/diskless index 9ccdfa80ed14..091ed1367c91 100644 --- a/etc/rc.d/diskless +++ b/etc/rc.d/diskless @@ -7,6 +7,7 @@ bpi="-i $4" fi /sbin/mdconfig -a -t malloc -s $1 -u $3 + /sbin/disklabel -r -w md$3 auto /sbin/newfs $bpi /dev/md$3c /sbin/mount /dev/md$3c $2 } diff --git a/etc/rc.d/resolv b/etc/rc.d/resolv index 9ccdfa80ed14..091ed1367c91 100644 --- a/etc/rc.d/resolv +++ b/etc/rc.d/resolv @@ -7,6 +7,7 @@ bpi="-i $4" fi /sbin/mdconfig -a -t malloc -s $1 -u $3 + /sbin/disklabel -r -w md$3 auto /sbin/newfs $bpi /dev/md$3c /sbin/mount /dev/md$3c $2 } diff --git a/etc/rc.d/tmp b/etc/rc.d/tmp index 9ccdfa80ed14..091ed1367c91 100644 --- a/etc/rc.d/tmp +++ b/etc/rc.d/tmp @@ -7,6 +7,7 @@ bpi="-i $4" fi /sbin/mdconfig -a -t malloc -s $1 -u $3 + /sbin/disklabel -r -w md$3 auto /sbin/newfs $bpi /dev/md$3c /sbin/mount /dev/md$3c $2 } diff --git a/etc/rc.d/var b/etc/rc.d/var index 9ccdfa80ed14..091ed1367c91 100644 --- a/etc/rc.d/var +++ b/etc/rc.d/var @@ -7,6 +7,7 @@ bpi="-i $4" fi /sbin/mdconfig -a -t malloc -s $1 -u $3 + /sbin/disklabel -r -w md$3 auto /sbin/newfs $bpi /dev/md$3c /sbin/mount /dev/md$3c $2 } diff --git a/etc/rc.devfs b/etc/rc.devfs index d8bb74811794..ffb67807af36 100644 --- a/etc/rc.devfs +++ b/etc/rc.devfs @@ -5,6 +5,7 @@ # if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf + source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi diff --git a/etc/rc.diskless2 b/etc/rc.diskless2 index 17b0bcb31203..c3069fa881df 100644 --- a/etc/rc.diskless2 +++ b/etc/rc.diskless2 @@ -7,6 +7,7 @@ # if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf + source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi diff --git a/etc/rc.firewall b/etc/rc.firewall index 37428808e7a2..a56cdf6e81b2 100644 --- a/etc/rc.firewall +++ b/etc/rc.firewall @@ -5,6 +5,7 @@ # Suck in the configuration variables. if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf + source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi