Subject: here's a script to check the validity of some /etc/rc.conf settings
To: NetBSD Userlevel Technical Discussion List <tech-userlevel@NetBSD.ORG>
From: Greg A. Woods <woods@weird.com>
List: tech-userlevel
Date: 10/19/2002 13:27:33
I have found the following script, which I've added to my /etc/daily,
helps to catch some typos in /etc/rc.conf (especially for long-running
systems which undergo startup configuration changes without being
rebooted), as well as pointing out which rc.d scripts from packages need
updating to meet full rc(8) features.

For example on my development system it reports:

	The following rc.conf settings are enabled but no script in /etc/rc.d
	claims it will use that setting.  (This may be because the scripts which
	use them do not support the 'rcvar' parameter, or possibly the variable
	name in /etc/rc.conf may be spelled wrong, or possibly the necessary
	/etc/rc.d script is missing.)
	
	        apache
	        apcupsd
	        pwcheckd
	        snmpd
	        snmptrapd

but only 'pwcheckd' is set but with no corresponding /etc/rc.d script (I
de-installed a test instance of Cyrus IMAPd a while ago).  The rest are
for packages which have ``incomplete'' rcd scripts (i.e. they don't
support the 'rcvar' parameter).

NOTE:  This script relies on the following changes to /etc/rc:

--- rc.sh       22 Nov 2000 06:10:03 -0000      1.1
+++ rc.sh       19 Oct 2002 17:21:35 -0000
@@ -XX,YY +II,JJ @@
-if [ "$1" = autoboot ]; then
+case "$1" in
+autoboot)
        autoboot=yes
        _rc_fast_run=yes        # run_rc_command(): do fast booting
-fi
+       ;;
+-d)
+       debug_echo=echo
+       ;;
+esac

@@ -41,8 +55,8 @@
 
 ordered_rc_d_files=$(rcorder ${_all_rc_d_files})
 
-for i in $ordered_rc_d_files; do
-       run_rc_script $i start
+for _rc_elem in $ordered_rc_d_files; do
+       $debug_echo run_rc_script $_rc_elem start
 done

 date

# verify that there is a way to "do" everything that's mentioned in
# /etc/rc.conf (and of course by implication in /etc/defaults/rc.conf)
#
if checkyesno check_rc_conf; then

	# a little helper function to filter lines like "var=VALUE"
	# and return only those that checkyesno would return true for
	#
	checkifyes ()
	{
		awk -F= '$2 ~ /[Yy][Ee][Ss]/ ||
			 $2 ~ /[Tt][Rr][Uu][Ee]/ ||
			 $2 ~ /[Oo][Nn]/ ||
			 $2 == 1 { print $1 }'
	}

	# First we find all the variables which are set "on" in
	# rc.conf.  To do that we have to first find a list of default
	# shell variables which appear to be "on".
	# 
	env -i sh -c "set" | checkifyes > alwayson.out

	# Note the following will always be set "on" but do not have
	# corresponding /etc/rc.d script rcvars, so we add them to the
	# list of default shell variables (then we sort the whole list).
	#
	cat <<__EOF__ >> alwayson.out
auto_ifconfig
do_rcshutdown
flushroutes
isdn_autoupdown
rc_configured
__EOF__

	sort -o alwayson.out alwayson.out

	# Next we find the list of all variables turned "on" in
	# /etc/rc.conf
	#
	env -i sh -c ". /etc/rc.conf; set" | \
		checkifyes | \
		sort > allrcconf.out

	# Finally we eliminate the "always on" variables from the
	# complete list of rc.conf variables leaving just the
	# variables which should be claimed as 'rcvar' variables by
	# /etc/rc.d/* scripts, and which are set "on".
	#
	comm -13 alwayson.out allrcconf.out > setrcconf.out

	# Next we find the list of 'rcvar's which all of the /etc/rc.d
	# scripts claim are turned on.
	#
	# note:  "/etc/rc -d" produces a list of scripts and we
	# transform that into a shell script to run them all with the
	# 'rcvar' parameter.
	#
	/etc/rc -d | awk '$2 ~ /etc/ {print $2  " rcvar"}' | \
		sh 2>/dev/null | \
		sed -e 's/^\$//;/^[ 	]*#/d;/^[ 	]*\$/d' | \
		checkifyes | \
		sort > willdo.out

	# Finally we compare the lists to find which rcvars are unclaimed
	#
	comm -23 setrcconf.out willdo.out > nocando.out
	if [ -s nocando.out ]; then
		echo ""
		echo "The following rc.conf settings are enabled but no script in /etc/rc.d"
		echo "claims it will use that setting.  (This may be because the scripts which"
		echo "use them do not support the 'rcvar' parameter, or possibly the variable"
		echo "name in /etc/rc.conf may be spelled wrong, or possibly the necessary"
		echo "/etc/rc.d script is missing.)"
		echo ""
		sed 's/^/	/' nocando.out
	fi
fi

-- 
								Greg A. Woods

+1 416 218-0098;            <g.a.woods@ieee.org>;           <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>