[PATCH] Overriding rc.conf in loader

From: Marcin Wisnicki <mwisnicki+freebsd_at_gmail.com>
Date: Sun, 4 Nov 2007 16:08:30 +0000 (UTC)
Hi

I thought it would be nice if there was a way to override rc.conf
variables during boot. Proposed patch implements this using kenv.

With it, you can override any rc variable from loader.conf by prefixing 
its name with 'rc.', some useful examples:

 # disable gdm
 set rc.gdm_enable=no

 # start only base scripts
 set rc.local_startup=

 # alternative rc.conf
 set rc.rc_conf_files=/etc/rc.conf.safe

I find it often more convenient than booting into single-user, remounting
rw and editing conf files.

If it's worth committing I can try to update rc.conf(5) & loader(8) manuals.


--- rc.subr.orig	2007-11-03 22:36:43.000000000 +0100
+++ rc.subr	2007-11-04 16:19:46.000000000 +0100
_at__at_ -901,6 +901,7 _at__at_
 #
 load_rc_config()
 {
+	local kvar
 	_name=$1
 	if [ -z "$_name" ]; then
 		err 3 'USAGE: load_rc_config name'
_at__at_ -912,6 +913,10 _at__at_
 		if [ -r /etc/defaults/rc.conf ]; then
 			debug "Sourcing /etc/defaults/rc.conf"
 			. /etc/defaults/rc.conf
+			debug "Trying to override rc_conf_files with kenv"
+			if kenv -q rc.rc_conf_files > /dev/null; then
+				rc_conf_files="$(kenv rc.rc_conf_files)"
+			fi
 			source_rc_confs
 		elif [ -r /etc/rc.conf ]; then
 			debug "Sourcing /etc/rc.conf (/etc/defaults/rc.conf doesn't exist)."
_at__at_ -923,6 +928,17 _at__at_
 		debug "Sourcing /etc/rc.conf.d/${_name}"
 		. /etc/rc.conf.d/"$_name"
 	fi
+	debug "Applying boot-time overrides of rc.conf"
+	_IFS=$IFS
+	IFS=${IFS#??}
+	for kvar in $(kenv); do
+		case "$kvar" in
+		rc.*)
+			eval "${kvar#rc.}"
+			;;
+		esac
+	done
+	IFS=$_IFS
 }
   
 #
Received on Sun Nov 04 2007 - 16:13:44 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:21 UTC