The sysrc command does not perform required set union/difference operations when asked to check if a variable contains certain values (or not) e.g. the following sequences of commands returns failure when it shouldn't: sysrc jail_list="jail1 jail2 jail3" && sysrc -c jail_list+=" jail2"
If I understand the code correctly the problem is that the case $mode in APPEND), REMOVE), *) is never reached if $CHECK_ONLY is set since sysrc:791 will continue the loop early.
I had a look, and it looks like the check logic does not account for APPEND and SUBTRACT operations. It just compares the existing value in the rc.conf file(s) to the value of the variable supplied on the command line. The APPEND/SUBTRACT logic does peform the union/difference calculation. The check logic can be moved after the APPEND/SUBTRACT logic, and use the "before" and "new" variables for the check comparison to get the correct result. I have created some regression tests for sysrc and a patch for this problem, and made a pull request with the the changes to github: https://github.com/freebsd/freebsd-src/pull/1664
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=c97460c4d97db1bd46dab9f2bdbc90cd1ed7757f commit c97460c4d97db1bd46dab9f2bdbc90cd1ed7757f Author: Michal Scigocki <michal.os@hotmail.com> AuthorDate: 2025-04-14 07:01:06 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2025-04-28 18:18:08 +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 usr.sbin/sysrc/sysrc | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-)