git: 51435c6e7bfd - main - sysrc: Enforce raw (-r) mode for all assignments

From: Devin Teske <dteske_at_FreeBSD.org>
Date: Wed, 18 Nov 2026 16:41:55 UTC
The branch main has been updated by dteske:

URL: https://cgit.FreeBSD.org/src/commit/?id=51435c6e7bfda456650ce1e5ed7302822ecda9ee

commit 51435c6e7bfda456650ce1e5ed7302822ecda9ee
Author:     Devin Teske <dteske@FreeBSD.org>
AuthorDate: 2026-11-18 16:36:43 +0000
Commit:     Devin Teske <dteske@FreeBSD.org>
CommitDate: 2026-11-18 16:36:43 +0000

    sysrc: Enforce raw (-r) mode for all assignments
    
    This is potentially a breaking change, warranting major version bump
    (7.x -> 8.0).
    
    Assignments with =, +=, or -= should not cause expansion of variables.
    For example, if rc.conf(5) has one="$1", two="$2", and foo="$one", and
    you execute `sysrc foo+=' $two'` you should get foo="$one $two" but
    at-present (version 7.x) sysrc stores foo="1 $two". This is because
    when querying current value, we read the expanded (read: not raw)
    value.
    
    Similary, if rc.conf has foo="$one $two" and you execute the command
    `sysrc foo-=' $two'` you should get foo="$one" but at-present sysrc
    erroneously stores foo="1 2". Since sysrc was reading the expanded
    value prior to modifying, it would read "1 2" prior to attempting to
    elide '$two' from the [space-separated] list (and since '$two' does
    not appear in the expanded value, no removal is performed and it
    subsequently wrote back the expanded value).
    
    Last but not least, for regular assignments with simple `=` the
    standard output message (without `-q') was misleading. Executing
    `sysrc cron_flags='$cron_flags -J 15'` would result in the message:
    `cron_flags:  ->  -J 15`. Worse, if you then executed the command
    `sysrc cron_flags="$( sysrc -nr cron_flags )"` the message would be:
    `cron_flags:  -J 15 ->  -J 15`. This is because both the before and
    after values queried are expanded instead of read raw. The program
    stores the correct value of "$cron_flags -J 15" but the message that
    is displayed to the user is misleading. While true that passing `-r'
    will correct the message in both cases, the expanded value should
    only be displayed when querying the value. That is to explain, that
    `sysrc -r cron_flags='$cron_flags -J 15'` will display correctly
    `cron_flags:  -> $cron_flags -J 15` and the latter command of
    `sysrc -r cron_flags="$( sysrc -nr cron_flags )"` correctly shows
    `cron_flags: $cron_flags -J 15 -> $cron_flags -J 15`.
    
    Point of keeping the display of expanded values on non-assignment
    queries is that sysrc is supposed to show you what the boot system
    will see, leaving `-r' available for querying raw values.
    
    Meanwhile, all forms of assignment should instead always show the
    unexpanded/raw values both in the before and after statements.
    
    A mechanism forcing the display of expanded values on assignments
    is not given. That is behavior we want to discontinue.
    
    Reviewed by:    kfv
    Differential Revision:  https://reviews.freebsd.org/D61656
---
 usr.sbin/sysrc/sysrc | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/usr.sbin/sysrc/sysrc b/usr.sbin/sysrc/sysrc
index efbe906d9fdd..2206cb640c1c 100644
--- a/usr.sbin/sysrc/sysrc
+++ b/usr.sbin/sysrc/sysrc
@@ -16,7 +16,7 @@ pgm="${0##*/}" # Program basename
 #
 # Version information
 #
-SYSRC_VERSION="7.4 Nov-14,2026"
+SYSRC_VERSION="8.0 Nov-16,2026"
 
 #
 # Options
@@ -730,11 +730,7 @@ while [ $# -gt 0 ]; do
 		#
 		case "$mode" in
 		APPEND)
-			if [ "$CHECK_ONLY$RAW" ]; then
-				before=$( f_sysrc_get_raw "$NAME" )
-			else
-				before=$( f_sysrc_get "$NAME" )
-			fi
+			before=$( f_sysrc_get_raw "$NAME" )
 			add="${1#*=}"
 			delim="${add%"${add#?}"}" # first character
 			oldIFS="$IFS"
@@ -756,11 +752,7 @@ while [ $# -gt 0 ]; do
 			[ "$SHOW_FILE" ] && before=$( f_sysrc_find "$NAME" )
 			;;
 		REMOVE)
-			if [ "$CHECK_ONLY$RAW" ]; then
-				before=$( f_sysrc_get_raw "$NAME" )
-			else
-				before=$( f_sysrc_get "$NAME" )
-			fi
+			before=$( f_sysrc_get_raw "$NAME" )
 			remove="${1#*=}"
 			delim="${remove%"${remove#?}"}" # first character
 			oldIFS="$IFS"
@@ -784,10 +776,8 @@ while [ $# -gt 0 ]; do
 		*) # ASSIGN
 			if [ "$SHOW_FILE" ]; then
 				before=$( f_sysrc_find "$NAME" )
-			elif [ "$CHECK_ONLY$RAW" ]; then
-				before=$( f_sysrc_get_raw "$NAME" )
 			else
-				before=$( f_sysrc_get "$NAME" )
+				before=$( f_sysrc_get_raw "$NAME" )
 			fi
 			new="${1#*=}"
 		esac
@@ -830,12 +820,10 @@ while [ $# -gt 0 ]; do
 				if [ ! "$QUIET" ]; then
 					if [ "$SHOW_FILE" ]; then
 						after=$( f_sysrc_find "$NAME" )
-					elif [ "$RAW" ]; then
+					else
 						after=$(
 							f_sysrc_get_raw "$NAME"
 						)
-					else
-						after=$( f_sysrc_get "$NAME" )
 					fi
 					echo -n "${SHOW_NAME:+$NAME$SEP}"
 					echo -n "$before${SHOW_EQUALS:+\" #}"