The branch stable/14 has been updated by markj:

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

commit f00a7faf050370d77292cac4c622a5a8d98ab13d
Author:     Michal Scigocki <[email protected]>
AuthorDate: 2025-04-14 07:01:06 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2025-06-01 19:53:29 +0000

    sysrc: Fix check flag logic for append and subtract
    
    When using sysrc with the check flag (-c), the append (+=) and subtract
    (-=) operations result in incorrect return values because on the check
    path the necessary union/difference calculation logic is not performed.
    
    However, the correct union/difference calculation is already performed
    when running without the check flag. We fix the issue on the check path
    by using the results from the existing union/difference calculation in
    the check logic to get the correct return values.
    
    PR:             279200
    Reviewed by:    markj
    MFC after:      1 month
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/1664
    
    (cherry picked from commit c97460c4d97db1bd46dab9f2bdbc90cd1ed7757f)
---
 usr.sbin/sysrc/sysrc | 52 +++++++++++++++++++++++++---------------------------
 1 file changed, 25 insertions(+), 27 deletions(-)

diff --git a/usr.sbin/sysrc/sysrc b/usr.sbin/sysrc/sysrc
index 1766cf7ab835..625ff5ca4efd 100644
--- a/usr.sbin/sysrc/sysrc
+++ b/usr.sbin/sysrc/sysrc
@@ -764,33 +764,6 @@ while [ $# -gt 0 ]; do
                        continue
                fi
 
-               #
-               # If `-c' is passed, simply compare and move on
-               #
-               if [ "$CHECK_ONLY" ]; then
-                       if ! IGNORED=$( f_sysrc_get "$NAME?" ); then
-                               status=$FAILURE
-                               [ "$VERBOSE" ] &&
-                                       echo "$NAME: not currently set"
-                               shift 1
-                               continue
-                       fi
-                       value=$( f_sysrc_get "$NAME" )
-                       if [ "$value" != "${1#*=}" ]; then
-                               status=$FAILURE
-                               if [ "$VERBOSE" ]; then
-                                       echo -n "$( f_sysrc_find "$NAME" ): "
-                                       echo -n "$NAME: would change from "
-                                       echo "\`$value' to \`${1#*=}'"
-                               fi
-                       elif [ "$VERBOSE" ]; then
-                               echo -n "$( f_sysrc_find "$NAME" ): "
-                               echo "$NAME: already set to \`$value'"
-                       fi
-                       shift 1
-                       continue
-               fi
-
                #
                # Determine both `before' value and appropriate `new' value
                #
@@ -848,6 +821,31 @@ while [ $# -gt 0 ]; do
                        new="${1#*=}"
                esac
 
+               #
+               # If `-c' is passed, simply compare and move on
+               #
+               if [ "$CHECK_ONLY" ]; then
+                       if ! IGNORED=$( f_sysrc_get "$NAME?" ); then
+                               status=$FAILURE
+                               [ "$VERBOSE" ] &&
+                                       echo "$NAME: not currently set"
+                               shift 1
+                               continue
+                       elif [ "$new" != "$before" ]; then
+                               status=$FAILURE
+                               if [ "$VERBOSE" ]; then
+                                       echo -n "$( f_sysrc_find "$NAME" ): "
+                                       echo -n "$NAME: would change from "
+                                       echo "\`$before' to \`$new'"
+                               fi
+                       elif [ "$VERBOSE" ]; then
+                               echo -n "$( f_sysrc_find "$NAME" ): "
+                               echo "$NAME: already set to \`$before'"
+                       fi
+                       shift 1
+                       continue
+               fi
+
                #
                # If `-N' is passed, simplify the output
                #

Reply via email to