git: 68d4c9592565 - main - sysrc: Restore alignment with rc(8) boot process

From: Devin Teske <dteske_at_FreeBSD.org>
Date: Thu, 26 Nov 2026 23:58:00 UTC
The branch main has been updated by dteske:

URL: https://cgit.FreeBSD.org/src/commit/?id=68d4c95925656e301be7bcaec72a6796cc02a00b

commit 68d4c95925656e301be7bcaec72a6796cc02a00b
Author:     Devin Teske <dteske@FreeBSD.org>
AuthorDate: 2026-11-26 23:53:53 +0000
Commit:     Devin Teske <dteske@FreeBSD.org>
CommitDate: 2026-11-26 23:53:53 +0000

    sysrc: Restore alignment with rc(8) boot process
    
    Fix 1 issue identified in post-commit review of d0a1676:
    
    POSTCR-d0a167652278ed81d259a1b77620b0c1cb9f72c8-1:
    set -f around source_rc_confs stops glob expansion of rc_conf_files,
    so sysrc no longer sees files that rc(8) sources
    
    Partially "revert" d0a167652278 with respect to RC_CONFS, `-f file`,
    rc_conf_files handling, and source_rc_confs invocation.
    
    Add an ATF test to ensure we maintain rc(8) alignment.
    
    Reported by:    llm-postcr
    Fixes:          d0a167652278 ("sysrc: Support special characters in file names")
---
 usr.sbin/sysrc/sysrc               | 17 +++++++--------
 usr.sbin/sysrc/sysrc.subr          | 28 +++++++++++++++++--------
 usr.sbin/sysrc/tests/sysrc_test.sh | 43 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 19 deletions(-)

diff --git a/usr.sbin/sysrc/sysrc b/usr.sbin/sysrc/sysrc
index 22f5b7f40dbb..f7b3a59129b3 100644
--- a/usr.sbin/sysrc/sysrc
+++ b/usr.sbin/sysrc/sysrc
@@ -16,7 +16,7 @@ pgm="${0##*/}" # Program basename
 #
 # Version information
 #
-SYSRC_VERSION="9.3.2 Nov-26,2026"
+SYSRC_VERSION="9.3.3 Nov-26,2026"
 
 #
 # Options
@@ -313,6 +313,11 @@ fi
 [ "$JAIL" -a "$ROOTDIR" ] &&
 	usage "-j and -R are mutually exclusive" # NOTREACHED
 
+#
+# rc(8) walks files with globbing on. Ignore sh -f invocation
+#
+set +f # glob
+
 #
 # Process `-L' flag
 #
@@ -324,7 +329,6 @@ if [ "$LIST_SERVICE_CONFS" ]; then
 	#
 	files=
 	[ $# -eq 0 ] && files=$( f_sysrc_get rc_conf_files )
-	set -f # noglob
 	for file in $files; do
 		if [ "$EXISTING_ONLY" ]; then
 			[ -e "$file" -a ! -d "$file" ] || continue
@@ -335,7 +339,6 @@ if [ "$LIST_SERVICE_CONFS" ]; then
 		list="$list $file"
 		[ "$VERBOSE$SHOW_EQUALS" ] || echo "$file"
 	done
-	set +f # glob
 	list="${list# }"
 	if [ $# -eq 0 ]; then
 		if [ "$VERBOSE" ]; then
@@ -450,11 +453,9 @@ if [ "$LIST_CONFS" ]; then
 	else
 		list=$( f_sysrc_get rc_conf_files )
 	fi
-	set -f # noglob
 	for item in $list; do
 		echo "$item"
 	done
-	set +f # glob
 	exit $SUCCESS
 fi
 
@@ -468,8 +469,7 @@ fi
 #
 errmsg="Exiting due to previous syntax errors"
 if [ "${RC_CONFS+set}" ]; then
-	( set -f # noglob
-	  for i in $RC_CONFS; do
+	( for i in $RC_CONFS; do
 	  	[ -e "$i" ] || continue
 	  	/bin/sh -n "$i" || exit $FAILURE
 	  done
@@ -478,7 +478,6 @@ if [ "${RC_CONFS+set}" ]; then
 else
 	/bin/sh -n "$RC_DEFAULTS" || die "$errmsg"
 	( . "$RC_DEFAULTS"
-	  set -f # noglob
 	  for i in $rc_conf_files; do
 	  	[ -e "$i" ] || continue
 	  	/bin/sh -n "$i" || exit $FAILURE
@@ -694,9 +693,7 @@ if [ "$SHOW_ALL" ]; then
 				rc_conf_files="${rc_conf_files% }"
 			fi
 
-			set -f # noglob
 			source_rc_confs
-			set +f # glob
 
 			#
 			# If passed `-a' (rather than `-A'), remove
diff --git a/usr.sbin/sysrc/sysrc.subr b/usr.sbin/sysrc/sysrc.subr
index c8c47b2a1e85..67fb7a1c3d65 100644
--- a/usr.sbin/sysrc/sysrc.subr
+++ b/usr.sbin/sysrc/sysrc.subr
@@ -291,8 +291,12 @@ f_sysrc_get()
 			_rc_confs_set=1
 		fi
 
-		set -f # noglob
+		# Walk the list the way source_rc_confs does, -f included
+		case "$-" in *f*) _noglob=1 ;; esac
+		set +f # glob
 		source_rc_confs > /dev/null 2>&1
+		[ "$_noglob" ] && set -f # noglob
+		unset _noglob
 
 		#
 		# If the query was for `rc_conf_files' AND after calling
@@ -988,19 +992,21 @@ f_sysrc_find()
 	[ "${RC_CONFS+set}" ] && rc_conf_files="$RC_CONFS"
 
 	#
-	# Determine if caller has set noglob before we disable filename
+	# Determine if caller has set noglob before we modify filename
 	# globbing, so we can later return to the inherited state.
 	#
 	case "$-" in
 	*f*) noglob=1 ;;
 	esac
-	set -f # noglob
 
 	#
 	# Reverse the order of files in rc_conf_files (the boot process sources
 	# these in order, so we will search them in reverse-order to find the
 	# last-assignment -- the one that ultimately effects the environment).
 	#
+	# NB: Expand rc_conf_files and `-f files` the way source_rc_confs does.
+	#
+	set +f # glob
 	for file in $rc_conf_files; do
 		conf_files="$file${conf_files:+ }$conf_files"
 	done
@@ -1015,6 +1021,9 @@ f_sysrc_find()
 	#
 	# Find which file matches assignment to the given variable name.
 	#
+	# NB: Do not re-expand globs in conf_files (already expanded above)
+	#
+	set -f # noglob
 	for file in $conf_files; do
 		[ -f "$file" -a -r "$file" ] || continue
 		if grep -Eq "$regex" $file; then
@@ -1348,7 +1357,8 @@ f_sysrc_delete()
 	case "$-" in
 	*f*) noglob=1 ;;
 	esac
-	set -f # noglob
+	# NB: Expand rc_conf_files and -f the way source_rc_confs does
+	set +f # glob
 	for file in ${RC_CONFS-$( f_sysrc_get rc_conf_files )}; do
 		[ -e "$file" ] || continue
 		f_shell_escape "$file" _file
@@ -1360,7 +1370,7 @@ f_sysrc_delete()
 			'mktemp -t "%s"' "$pgm"
 		then
 			echo "$tmpfile" >&2
-			[ "$noglob" ] || set +f # glob
+			[ "$noglob" ] && set -f # noglob
 			return $FAILURE
 		fi
 
@@ -1398,7 +1408,7 @@ f_sysrc_delete()
 			f_err "$msg_previous_syntax_errors\n" \
 			      "$pgm" "$file"
 			rm -f "$tmpfile"
-			[ "$noglob" ] || set +f # glob
+			[ "$noglob" ] && set -f # noglob
 			return $FAILURE
 		fi
 
@@ -1408,7 +1418,7 @@ f_sysrc_delete()
 		if [ ! -w "$file" ]; then
 			f_err "$msg_permission_denied\n" "$pgm" "$file"
 			rm -f "$tmpfile"
-			[ "$noglob" ] || set +f # glob
+			[ "$noglob" ] && set -f # noglob
 			return $FAILURE
 		fi
 
@@ -1418,12 +1428,12 @@ f_sysrc_delete()
 		if ! f_eval_catch -de $funcname mv \
 			"mv '%s' '%s'" "$tmpfile" "$_file"
 		then
-			[ "$noglob" ] || set +f
+			[ "$noglob" ] && set -f # noglob
 			return $FAILURE
 		fi
 	done
 
-	[ "$noglob" ] || set +f # glob
+	[ "$noglob" ] && set -f # noglob
 	return $SUCCESS
 }
 
diff --git a/usr.sbin/sysrc/tests/sysrc_test.sh b/usr.sbin/sysrc/tests/sysrc_test.sh
index b21fae3e057e..3d188c189f7c 100644
--- a/usr.sbin/sysrc/tests/sysrc_test.sh
+++ b/usr.sbin/sysrc/tests/sysrc_test.sh
@@ -464,6 +464,48 @@ F_flag_assign_body()
 	atf_check -o inline:"p=\"${SYSRC_CONF}\"\n" cat "${SYSRC_CONF}"
 }
 
+atf_test_case rc_conf_files_glob cleanup
+rc_conf_files_glob_head()
+{
+	atf_set "descr" "rc_conf_files globs expand for boot, -f, and RC_CONFS"
+}
+rc_conf_files_glob_body()
+{
+	local extra files
+
+	mkdir rc.conf.d
+	extra="${PWD}/rc.conf.d/extra.conf"
+	printf '%s\n' 'base="from-rc"' > "${PWD}/rc.conf"
+	printf '%s\n' 'gvar="from-glob"' > "$extra"
+
+	RC_DEFAULTS="${PWD}/rc_defaults.conf"
+	cat > "${RC_DEFAULTS}" << EOF
+source_rc_confs() {
+	local i
+	for i in \${rc_conf_files}; do
+		[ -r "\$i" ] && . "\$i"
+	done
+}
+rc_conf_files="${PWD}/rc.conf ${PWD}/rc.conf.d/*.conf"
+EOF
+	export RC_DEFAULTS
+
+	atf_check -o inline:"${PWD}/rc.conf\n${extra}\n" sysrc -l
+	atf_check -o inline:'gvar: from-glob\n' sysrc gvar
+	# -f and RC_CONFS carry the rc_conf_files value, glob included
+	files=$( sysrc -nD rc_conf_files )
+	atf_check -o inline:'gvar: from-glob\n' sysrc -f "$files" gvar
+	atf_check -o inline:'gvar: from-glob\n' \
+	    env RC_CONFS="$files" sysrc gvar
+	atf_check -o inline:'gvar: from-glob -> NEW\n' sysrc gvar=NEW
+	atf_check -o inline:'gvar="NEW"\n' cat "$extra"
+	atf_check -o inline:'base="from-rc"\n' cat "${PWD}/rc.conf"
+}
+rc_conf_files_glob_cleanup()
+{
+	unset RC_DEFAULTS
+}
+
 atf_test_case r_flag
 r_flag_head()
 {
@@ -653,5 +695,6 @@ atf_init_test_cases()
 	atf_add_test_case f_flag
 	atf_add_test_case F_flag
 	atf_add_test_case F_flag_assign
+	atf_add_test_case rc_conf_files_glob
 	atf_add_test_case r_flag
 }