Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Aug 1999 09:57:08 -0700
From:      Doug <Doug@gorean.org>
To:        freebsd-hackers@freebsd.org
Subject:   Re: Please review: rc file changes
Message-ID:  <37C6C364.EA3769CB@gorean.org>
References:  <37C63094.8350A91B@gorean.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------1A0A0395E93438FADF6CBC6E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Doug wrote:
> 
> Greetings,
> 
>         As previously discussed, here is a first draft of the rc* script mods. I
> consider the first step in this process to be Jordan's cleanup of the
> variable syntax. This is step 2, which most notably converts test's dealing
> with variables to case wherever possible. It also does the following.
> 
> 1. -f -> -r wherever it makes sense
> 2. value ) instead of value) for case statements
> 3. All cases of [, test, ; then, etc. converted to:
> 
> if [ blah ]; then
> 
> 4. Made
> # Comment
> #
> commands more consistent
> 
> 5. Stripped whitespace off the end of a few lines
> 
>         The attached diff is to rc, and was generated with -ubB to ease
> understanding of the substantive changes. You can view the actual file at
> http://gorean.org/rc. I would appreciate y'all reviewing these changes for
> style, substance, or anything else relevant to the matter at hand. My hope
> is that any modifications can be discussed prior to my doing the rest of
> the work, which I plan to tackle this weekend. There are also a few
> questions sprinkled into the file, comments or suggestions on those are
> welcome.
> 
>         This version of the file is tested lightly, which is to say that I
> booted with it after my upgrade to the most recent sources on -current tonight.
> Obviously more rigorous testing will be necessary before this gets
> committed, although the changes are extremely straightforward.
> 
> Questions:
> 
> 1. Under what circumstances would $early_nfs_mounts be set? The only
> mention of this variable that I could find is in /etc/rc, and I can't see
> where it would be set.
> 
> 2. Do we want to move to 'logger' instead of echo for the various little
> statements in the rc* files during boot? I for one would highly recommend
> this change, since it makes remote administration TONS easier. However the
> last time it came up I seem to remember it being one of those "religious"
> issues...
> 
> 3. Anything else I should be looking at in this phase of the game?

	Ok, revised diff attached. I made the case indentation change and some of
sheldon's suggestions are incorporated. I also neglected to mention
previously that I tuned up a few of the comments in the file, as well as
error output. I also was more rigorous about making whitespace consisten on
this pass. Removing double spaces, converting spaces to tabs, etc. This is
much more like what I want the final version to look like. All of the above
still applies, except that due to the more "normal" indentation a straight
diff -u is more readable. 

	Assuming this works for everyone, I will proceed with the other rc*, etc.
scripts, except rc.network which sheldon informed me he is currently
working on. 

Doug
--------------1A0A0395E93438FADF6CBC6E
Content-Type: text/plain; charset=us-ascii;
 name="rc.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="rc.diff"

--- /usr/src/etc/rc	Thu Aug 26 20:56:36 1999
+++ rc	Fri Aug 27 09:52:39 1999
@@ -8,24 +8,25 @@
 # and the console is the controlling terminal.
 
 # Note that almost all the user-configurable behavior is no longer in
-# this file, but rather in /etc/defaults/rc.conf.  Please check this file
+# this file, but rather in /etc/defaults/rc.conf. Please check that file
 # first before contemplating any changes here.
 
 stty status '^T'
 
 # Set shell to ignore SIGINT (2), but not children;
 # shell catches SIGQUIT (3) and returns to single user after fsck.
+#
 trap : 2
 trap : 3	# shouldn't be needed
 
-HOME=/; export HOME
+HOME=/
 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
-export PATH
+export HOME PATH
 
-# BOOTP diskless boot.  We have to run the rc file early in order to
+# BOOTP diskless boot. We have to run the rc file early in order to
 # retarget various config files.
 #
-if [ -f /etc/rc.diskless1 ]; then
+if [ -r /etc/rc.diskless1 ]; then
 	dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
 	if [ ${dlv:=0} != 0 ]; then
 		. /etc/rc.diskless1
@@ -34,59 +35,68 @@
 
 # If there is a global system configuration file, suck it in.
 #
-if [ -f /etc/defaults/rc.conf ]; then
+if [ -r /etc/defaults/rc.conf ]; then
 	. /etc/defaults/rc.conf
-elif [ -f /etc/rc.conf ]; then
+elif [ -r /etc/rc.conf ]; then
 	. /etc/rc.conf
 fi
 
 # Configure ccd devices.
-if [ -f /etc/ccd.conf ]; then
+#
+if [ -r /etc/ccd.conf ]; then
 	ccdconfig -C
 fi
 
-if [ "${start_vinum}" = "YES" ]; then
+case ${start_vinum} in
+[Yy][Ee][Ss] )
 	vinum start
-elif [ -n "${vinum_drives}" ]; then
-	vinum read ${vinum_drives}
-fi
+	;;
+* )
+	if [ -n "${vinum_drives}" ]; then
+		vinum read ${vinum_drives}
+	fi
+	;;
+esac
 
 swapon -a
 
-if [ "$1" = "autoboot" ]; then
+case $1 in
+autoboot )
 	echo Automatic reboot in progress...
 	fsck -p
 	case $? in
-	0)
+	0 )
 		;;
-	2)
+	2 )
 		exit 1
 		;;
-	4)
+	4 )
 		reboot
 		echo "reboot failed... help!"
 		exit 1
 		;;
-	8)
+	8 )
 		echo "Automatic file system check failed... help!"
 		exit 1
 		;;
-	12)
+	12 )
 		echo "Reboot interrupted"
 		exit 1
 		;;
-	130)
+	130 )
 		# interrupt before catcher installed
 		exit 1
 		;;
-	*)
+	* )
 		echo "Unknown error in reboot"
 		exit 1
 		;;
 	esac
-else
+	;;
+* )
 	echo Skipping disk checks ...
-fi
+	;;
+esac
 
 set -T
 trap "echo 'Reboot interrupted'; exit 1" 3
@@ -94,35 +104,49 @@
 # root normally must be read/write, but if this is a BOOTP NFS
 # diskless boot it does not have to be.
 #
-
-if [ "${root_rw_mount}" != "NO" ]; then
+case ${root_rw_mount} in
+[Nn][Oo] )
+	;;
+* )
 	mount -u -o rw /
-fi
+	;;
+esac
 
-if [ $? != 0 ]; then
-	echo "Filesystem mount failed, startup aborted"
+case $? in
+0 )
+	;;
+* )
+	echo "Mounting root filesystem rw failed, startup aborted"
 	exit 1
-fi
+	;;
+esac
 
 umount -a >/dev/null 2>&1
 
-if [ "${early_nfs_mounts}" != "YES" ]; then
-	mount -a -t nonfs
-else
+# Where/how would this get set?
+#
+case ${early_nfs_mounts} in
+[Yy][Ee][Ss] )
 	mount -a
-fi
-if [ $? != 0 ]; then
-	echo "Filesystem mount failed, startup aborted"
+	;;
+* )
+	mount -a -t nonfs
+	;;
+esac
+
+case $? in
+0 )
+	;;
+* )
+	echo "Mounting /etc/fstab filesystems failed, startup aborted"
 	exit 1
-fi
+	;;
+esac
 
 # Run custom disk mounting function here
 #
-
-if [ -n "${diskless_mount}" ]; then
-	if [ -f "${diskless_mount}" ]; then
+if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
 		sh ${diskless_mount}
-	fi
 fi
 
 adjkerntz -i
@@ -148,66 +172,81 @@
 fi
 
 # Add additional swapfile, if configured.
-if [ "${swapfile}" != "NO" -a -w "${swapfile}" -a -b /dev/vn0b ]; then
-	echo "Adding ${swapfile} as additional swap."
-	vnconfig /dev/vn0b ${swapfile} && swapon /dev/vn0b
-fi
+#
+case ${swapfile} in
+[Nn][Oo] )
+	;;
+* )
+	if [ -w "${swapfile}" -a -b /dev/vn0b ]; then
+		echo "Adding ${swapfile} as additional swap."
+		vnconfig /dev/vn0b ${swapfile} && swapon /dev/vn0b
+	fi
+	;;
+esac
 
-# set sysctl variables early as we can
-if [ -f /etc/rc.sysctl ]; then
+# Set sysctl variables as early as we can
+#
+if [ -r /etc/rc.sysctl ]; then
 	. /etc/rc.sysctl
 fi
 
-# configure serial devices
-if [ -f /etc/rc.serial ]; then
+# Configure serial devices
+#
+if [ -r /etc/rc.serial ]; then
 	. /etc/rc.serial
 fi
 
-# start up PC-card configuration
-if [ -f /etc/rc.pccard ]; then
+# Start up PC-card configuration
+#
+if [ -r /etc/rc.pccard ]; then
 	. /etc/rc.pccard
 fi
 
-# start up the initial network configuration.
-if [ -f /etc/rc.network ]; then
+# Start up the initial network configuration.
+#
+if [ -r /etc/rc.network ]; then
 	. /etc/rc.network	# We only need to do this once.
 	network_pass1
 fi
 
+# Retest for early_nfs here?
+#
 echo -n "Mounting NFS file systems"
 mount -a -t nfs
 echo .
 
 # Whack the pty perms back into shape.
+#
 chflags 0 /dev/tty[pqrsPQRS]*
 chmod 666 /dev/tty[pqrsPQRS]*
 chown root:wheel /dev/tty[pqrsPQRS]*
 
-# clean up left-over files
+# Clean up left-over files
+#
 clean_var			# If it hasn't already been done
 rm /var/run/clean_var
 
-#
-# Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
+# Clearing /tmp at boot-time seems to have a long tradition. It doesn't
 # help in any way for long-living systems, and it might accidentally
 # clobber files you would rather like to have preserved after a crash
 # (if not using mfs /tmp anyway).
 #
 # See also the example of another cleanup policy in /etc/periodic/daily.
 #
-if [ "${clear_tmp_enable}" = "YES" ]; then
+case ${clear_tmp_enable} in
+[Yy][Ee][Ss] )
 	echo clearing /tmp
-
 	# prune quickly with one rm, then use find to clean up /tmp/[lq]*
 	# (not needed with mfs /tmp, but doesn't hurt there...)
 	(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
-	    find -d . ! -name . ! -name lost+found ! -name quota.user \
-	    ! -name quota.group -exec rm -rf -- {} \;)
-
-fi
+		find -d . ! -name . ! -name lost+found ! -name quota.user \
+		! -name quota.group -exec rm -rf -- {} \;)
+	;;
+esac
 
-# Remove X lock files, since they will prevent you from restarting X11 
+# Remove X lock files, since they will prevent you from restarting X11
 # after a system crash.
+#
 rm -f /tmp/.X*-lock /tmp/.X11-unix/*
 
 # snapshot any kernel -c changes back to disk here <someday>
@@ -217,78 +256,97 @@
 # start system logging and name service (named needs to start before syslogd
 # if you don't have a /etc/resolv.conf)
 #
-if [ "${syslogd_enable}" = "YES" ]; then
+case ${syslogd_enable} in
+[Yy][Ee][Ss] )
 	# Transitional symlink (for the next couple of years :) until all
-	# binaries had a chance to move towards /var/run/log.
+	# binaries have had a chance to move towards /var/run/log.
 	if [ ! -h /dev/log ] ; then
 		# might complain for r/o root f/s
 		ln -sf /var/run/log /dev/log
 	fi
 
 	rm -f /var/run/log
-	echo -n ' syslogd';		syslogd ${syslogd_flags}
-fi
+	echo -n ' syslogd';	syslogd ${syslogd_flags}
+	;;
+esac
+
 echo '.'
 
 # enable dumpdev so that savecore can see it
 # /var/crash should be a directory or a symbolic link
 # to the crash directory if core dumps are to be saved.
-if [ "${dumpdev}" != "NO" -a -e ${dumpdev} -a -d /var/crash ]; then
-	dumpon ${dumpdev}
-	echo -n checking for core dump...
-	savecore /var/crash
-fi
+#
+case ${dumpdev} in
+[Nn][Oo] )
+	;;
+* )
+	if [ -e ${dumpdev} -a -d /var/crash ]; then
+		dumpon ${dumpdev}
+		echo -n checking for core dump...
+		savecore /var/crash
+	fi
+	;;
+esac
 
 if [ -n "${network_pass1_done}" ]; then
 	network_pass2
 fi
 
 # Enable/Check the quotas (must be after ypbind if using NIS)
-if [ "${enable_quotas}" = "YES" ]; then
+#
+case ${enable_quotas} in
+[Yy][Ee][Ss] )
+	case ${check_quotas} in
+	[Yy][Ee][Ss] )
+		echo -n 'checking quotas:'
+		quotacheck -a
+		echo ' done.'
+		;;
+	esac
 
-    # Only check quotas if they have been previously enabled, and requested
-    if [ "${check_quotas}" = "YES" ]; then
-            echo -n 'checking quotas:'
-            quotacheck -a
-            echo ' done.'
-    fi
-
-        echo -n 'enabling quotas:'
-        quotaon -a
-        echo ' done.'
-fi
+	echo -n 'enabling quotas:'
+	quotaon -a
+	echo ' done.'
+	;;
+esac
 
 if [ -n "${network_pass2_done}" ]; then
 	network_pass3
 fi
 
 
-# build ps databases
-kvm_mkdb 
+# Build ps databases
+#
+kvm_mkdb
 dev_mkdb
 
-# check the password temp/lock file
-if [ -f /etc/ptmp ]
-then
+# Check the password temp/lock file
+#
+if [ -e /etc/ptmp ]; then
 	logger -s -p auth.err \
 	"password file may be incorrect -- /etc/ptmp exists"
 fi
 
-if [ "${accounting_enable}" = "YES" -a -d /var/account ]; then
-	echo 'turning on accounting'
-	if [ ! -e /var/account/acct ]; then
-		touch /var/account/acct
+case ${accounting_enable} in
+[Yy][Ee][Ss] )
+	if [ -d /var/account ]; then
+		echo 'turning on accounting'
+		if [ ! -e /var/account/acct ]; then
+			touch /var/account/acct
+		fi
+		accton /var/account/acct
 	fi
-	accton /var/account/acct
-fi
+	;;
+esac
 
-# Make shared lib searching a little faster.  Leave /usr/lib first if you
+# Make shared lib searching a little faster. Leave /usr/lib first if you
 # add your own entries or you may come to grief.
+#
 if [ -x /sbin/ldconfig ]; then
 	if [ "`/usr/bin/objformat`" = "elf" ]; then
 		_LDC=/usr/lib
 		for i in ${ldconfig_paths}; do
-			if test -d ${i}; then
+			if [ -d ${i} ]; then
 				_LDC="${_LDC} ${i}"
 			fi
 		done
@@ -302,7 +360,7 @@
 		: ${ldconfig_paths_aout=${ldconfig_paths}}
 		_LDC=/usr/lib/aout
 		for i in ${ldconfig_paths_aout}; do
-			if test -d ${i}; then
+			if [ -d ${i} ]; then
 				_LDC="${_LDC} ${i}"
 			fi
 		done
@@ -314,47 +372,65 @@
 # Now start up miscellaneous daemons that don't belong anywhere else
 #
 echo -n starting standard daemons:
-if [ "${inetd_enable}" != "NO" ]; then
+case ${inetd_enable} in
+[Nn][Oo] )
+	;;
+* )
 	echo -n ' inetd';	inetd ${inetd_flags}
-fi
+	;;
+esac
 
-if [ "${cron_enable}" != "NO" ]; then
+case ${cron_enable} in
+[Nn][Oo] )
+	;;
+* )
 	echo -n ' cron';	cron
-fi
+	;;
+esac
 
-if [ "${lpd_enable}" = "YES" ]; then
-	echo -n ' printer';		${lpd_program} ${lpd_flags}
-fi
-
-if [ "${sendmail_enable}" = "YES" -a -r /etc/sendmail.cf ]; then
-	echo -n ' sendmail';	/usr/sbin/sendmail ${sendmail_flags}
-fi
+case ${lpd_enable} in
+[Yy][Ee][Ss] )
+	echo -n ' printer';	${lpd_program} ${lpd_flags}
+	;;
+esac
+
+case ${sendmail_enable} in
+[Yy][Ee][Ss] )
+	if [ -r /etc/sendmail.cf ]; then
+		echo -n ' sendmail';	/usr/sbin/sendmail ${sendmail_flags}
+	fi
+	;;
+esac
 
-if [ "${usbd_enable}" = "YES" ]; then
+case ${usbd_enable} in
+[Yy][Ee][Ss] )
 	echo -n ' usbd';	/usr/sbin/usbd ${usbd_flags}
-fi
+	;;
+esac
 
 echo '.'
 
-# configure implementation specific stuff
+# Configure implementation specific stuff
+#
 arch=`uname -m`
-if [ -f /etc/rc.${arch} ]; then
+if [ -r /etc/rc.${arch} ]; then
 	. /etc/rc.${arch}
 fi
 
 # Recover vi editor files.
+#
 vibackup=`echo /var/tmp/vi.recover/vi.*`
 if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
 	echo 'Recovering vi editor sessions'
 	for i in ${vibackup}; do
 		# Only test files that are readable.
-		if test ! -r ${i}; then
+		if [ ! -r ${i} ]; then
 			continue
 		fi
 
 		# Unmodified nvi editor backup files either have the
-		# execute bit set or are zero length.  Delete them.
-		if test -x ${i} -o ! -s ${i}; then
+		# execute bit set or are zero length. Delete them.
+		if [ -x ${i} -o ! -s ${i} ]; then
 			rm -f ${i}
 		fi
 	done
@@ -365,7 +441,7 @@
 	if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
 		for i in ${virecovery}; do
 			# Only test files that are readable.
-			if test ! -r ${i}; then
+			if [ ! -r ${i} ]; then
 				continue
 			fi
 
@@ -373,7 +449,7 @@
 			# corrupted, or that have no corresponding backup file.
 			# Else send mail to the user.
 			recfile=`awk '/^X-vi-recover-path:/{print $2}' < ${i}`
-			if test -n "${recfile}" -a -s "${recfile}"; then
+			if [ -n "${recfile}" -a -s "${recfile}" ]; then
 				sendmail -t < ${i}
 			else
 				rm -f ${i}
@@ -382,26 +458,40 @@
 	fi
 fi
 
-# make a bounds file for msgs(1) if there isn't one already
+# Make a bounds file for msgs(1) if there isn't one already
+# "Delete important files with symlink" security hole?
+#
 if [ ! -f /var/msgs/bounds ]; then
 	echo 0 > /var/msgs/bounds
 fi
 
-# for each valid dir in $local_startup, search for init scripts matching *.sh
-if [ "${local_startup}" != "NO" ]; then
+# For each valid dir in $local_startup, search for init scripts matching *.sh
+#
+case ${local_startup} in
+[Nn][Oo] )
+	;;
+* )
 	echo -n 'Local package initialization:'
 	for dir in ${local_startup}; do
-		[ -d ${dir} ] && for script in ${dir}/*.sh; do
-			[ -x ${script} ] && \
+		if [ -d ${dir} ]; then
+			for script in ${dir}/*.sh; do
+			if [ -x ${script} ]; then
 				(set -T ; trap 'exit 1' 2 ; ${script} start)
-		done
+			fi
+			done
+		fi
 	done
 	echo .
-fi
+	;;
+esac
 
-if [ "${update_motd}" != "NO" ]; then
+case ${update_motd} in
+[Nn][Oo] )
+	;;
+* )
 	T=`mktemp /tmp/_motd.XXXXXX`
-	if [ $? -eq 0 ]; then
+	case $? in
+	0 )
 		uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
 		awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
 		cmp -s ${T} /etc/motd || {
@@ -409,39 +499,48 @@
 			chmod 644 /etc/motd
 		}
 		rm -f ${T}
-	fi
-fi
+		;;
+	esac
+	;;
+esac
 
-# Run rc.devfs if present to customize devfs
-[ -f /etc/rc.devfs ] && sh /etc/rc.devfs
+# Run rc.devfs if readable to customize devfs
+#
+if [ -r /etc/rc.devfs ]; then
+	sh /etc/rc.devfs
+fi
 
-# Do traditional (but rather obsolete) rc.local file if it exists.  If you
+# Do traditional (but rather obsolete) rc.local file if it exists. If you
 # use this file and want to make it programmatic, source /etc/defaults/rc.conf
 # in /etc/rc.local and add your custom variables to /etc/rc.conf, as
-# shown below.  Please do not put local extensions into /etc/rc itself.
+# shown below. Please do not put local extensions into /etc/rc itself.
 # Use /etc/rc.local
 #
-# ---- rc.local  ----
-#     if [ -f /etc/defaults/rc.conf ]; then
-#             . /etc/defaults/rc.conf
-#     fi
-# 
-#     ... additional startup conditionals ...
-# ---- rc.local  ---- 
-# 
-if [ -f /etc/rc.local ]; then
+# ---- rc.local ----
+#	if [ -r /etc/defaults/rc.conf ]; then
+#		. /etc/defaults/rc.conf
+#	fi
+#
+#	... additional startup conditionals ...
+# ---- rc.local ----
+#
+if [ -r /etc/rc.local ]; then
 	echo -n 'starting local daemons:'
-        sh /etc/rc.local
+	sh /etc/rc.local
 	echo '.'
 fi
 
-# Raise kernel security level.  This should be done only after `fsck' has
+# Raise kernel security level. This should be done only after `fsck' has
 # repaired local file systems if you want the securelevel to be greater than 1.
-if [ "${kern_securelevel_enable}" = "YES" -a "${kern_securelevel}" -ge 0 ]; 
-then
-	echo 'Raising kernel security level'
-	sysctl -w kern.securelevel=${kern_securelevel}
-fi
+#
+case ${kern_securelevel_enable} in
+[Yy][Ee][Ss] )
+	if [ "${kern_securelevel}" -ge 0 ]; then
+		echo 'Raising kernel security level'
+		sysctl -w kern.securelevel=${kern_securelevel}
+	fi
+	;;
+esac
 
 date
 exit 0

--------------1A0A0395E93438FADF6CBC6E--



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?37C6C364.EA3769CB>