Date: Sun, 4 Nov 2007 16:08:30 +0000 (UTC) From: Marcin Wisnicki <mwisnicki+freebsd@gmail.com> To: freebsd-current@freebsd.org Subject: [PATCH] Overriding rc.conf in loader Message-ID: <fgkqpu$rhp$1@ger.gmane.org>
next in thread | raw e-mail | index | archive | help
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
@@ -901,6 +901,7 @@
#
load_rc_config()
{
+ local kvar
_name=$1
if [ -z "$_name" ]; then
err 3 'USAGE: load_rc_config name'
@@ -912,6 +913,10 @@
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)."
@@ -923,6 +928,17 @@
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
}
#
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?fgkqpu$rhp$1>
