Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177713412
D61659.1795108270.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
D61659.1795108270.diff
View Options
diff --git a/usr.sbin/sysrc/sysrc b/usr.sbin/sysrc/sysrc
--- a/usr.sbin/sysrc/sysrc
+++ b/usr.sbin/sysrc/sysrc
@@ -16,7 +16,7 @@
#
# Version information
#
-SYSRC_VERSION="8.2 Nov-16,2026"
+SYSRC_VERSION="8.3 Nov-16,2026"
#
# Options
@@ -63,7 +63,7 @@
usage()
{
f_err "Usage: %s [OPTIONS] %s\n" "$pgm" \
- "{name[[+|-]=value] ... | -a | -A | -l | -L [name ...]}"
+ "{name[[+|-|.]=value] ... | -a | -A | -l | -L [name ...]}"
f_err "Try \`%s --help' for more information.\n" "$pgm"
die
}
@@ -77,7 +77,7 @@
local optfmt="\t%-11s%s\n"
local envfmt="\t%-17s%s\n"
- f_err "Usage: %s [OPTIONS] name[[+|-]=value] ...\n" "$pgm"
+ f_err "Usage: %s [OPTIONS] name[[+|-|.]=value] ...\n" "$pgm"
f_err "Usage: %s [OPTIONS] -a | -A\n" "$pgm"
f_err "Usage: %s [OPTIONS] -l | -L [name ...]\n" "$pgm"
@@ -332,6 +332,7 @@
for name in "$@"; do
# NB: shell expansion syntax removed first
name="${name%%:[+=-]*}"
+ name="${name%%.=*}" # string append
name="${name%%[%#+=-]*}"
[ "$name" = "${name#*[!$VALID_VARNAME_CHARS]}" ] || die \
"%s: %s: name contains characters not allowed in shell" \
@@ -688,8 +689,9 @@
NAME="${1%%=*}"
case "$NAME" in
- *+) mode=APPEND NAME="${NAME%+}" ;;
- *-) mode=REMOVE NAME="${NAME%-}" ;;
+ *+) mode=LISTAPPEND NAME="${NAME%+}" ;;
+ *-) mode=LISTREMOVE NAME="${NAME%-}" ;;
+ *.) mode=STRAPPEND NAME="${NAME%.}" ;;
*) mode=ASSIGN
esac
@@ -729,7 +731,7 @@
# Determine both `before' value and appropriate `new' value
#
case "$mode" in
- APPEND)
+ LISTAPPEND)
before=$( f_sysrc_get_raw "$NAME" )
add="${1#*=}"
delim="${add%"${add#?}"}" # first character
@@ -753,7 +755,7 @@
unset add delim oldIFS a skip b
[ "$SHOW_FILE" ] && before=$( f_sysrc_find "$NAME" )
;;
- REMOVE)
+ LISTREMOVE)
before=$( f_sysrc_get_raw "$NAME" )
remove="${1#*=}"
delim="${remove%"${remove#?}"}" # first character
@@ -777,6 +779,15 @@
unset remove delim oldIFS b add r
[ "$SHOW_FILE" ] && before=$( f_sysrc_find "$NAME" )
;;
+ STRAPPEND)
+ # Space before the text if the value is non-NULL
+ before=$( f_sysrc_get_raw "$NAME" )
+ add="${1#*=}"
+ new="$add"
+ [ "$before" ] && new="$before $add"
+ unset add
+ [ "$SHOW_FILE" ] && before=$( f_sysrc_find "$NAME" )
+ ;;
*) # ASSIGN
if [ "$SHOW_FILE" ]; then
before=$( f_sysrc_find "$NAME" )
diff --git a/usr.sbin/sysrc/sysrc.8 b/usr.sbin/sysrc/sysrc.8
--- a/usr.sbin/sysrc/sysrc.8
+++ b/usr.sbin/sysrc/sysrc.8
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd November 15, 2026
+.Dd November 17, 2026
.Dt SYSRC 8
.Os
.Sh NAME
@@ -37,7 +37,7 @@
.Op Fl s Ar name
.Op Fl f Ar file
.Op Fl j Ar jail | Fl R Ar dir
-.Ar name Ns Op Ns Oo +|- Oc Ns = Ns Ar value
+.Ar name Ns Op Ns Oo +|-|. Oc Ns = Ns Ar value
.Ar ...
.Nm
.Op Fl cdDeEFhinNqrvx
@@ -200,11 +200,14 @@
.Pq but unlike Xr sysctl 8 ,
.Ql name+=value
is supported for adding items to values
-.Pq see APPENDING VALUES
-and
+.Pq see APPENDING VALUES ,
.Ql name-=value
is supported for removing items from values
-.Pq see SUBTRACTING VALUES .
+.Pq see SUBTRACTING VALUES ,
+and
+.Ql name.=value
+is supported for appending text
+.Pq see APPENDING TEXT .
.Pp
However, while
.Xr sysctl 8
@@ -379,6 +382,69 @@
.Nm
removes all occurrences of all items provided
and collapses extra delimiters between items.
+.Sh APPENDING TEXT
+When using the
+.Ql key.=value
+syntax,
+.Nm
+appends
+.Ar value
+to the current value as one string.
+The first character is not a delimiter, and
+.Ar value
+is not split into items.
+If the current value is non-NULL, one space is inserted before the text.
+If no
+.Ar value
+is given
+.Pq Ql key.= ,
+nothing is changed and success is returned.
+.Pp
+The text operator
+.Ql .=
+suits option strings stored in
+.Ql *_flags
+variables.
+For example, with
+.Va cron_flags
+set to
+.Dq $cron_flags -j 15 :
+.Bl -item -offset indent
+.It
+.Nm
+cron_flags.="-J 15"
+.Dl # `$cron_flags -j 15' -> `$cron_flags -j 15 -J 15'
+.El
+.Pp
+The list operator
+.Ql +=
+does not do this
+.Pq see Sx APPENDING VALUES .
+.Ql cron_flags+="-J 15"
+has two items,
+.Dq -J
+and
+.Dq 15 .
+Because
+.Dq 15
+is already present, only
+.Dq -J
+is added, and the stored text becomes
+.Dq $cron_flags -j 15 -J .
+.Pp
+To join with another delimiter, or with none, manually read the raw value and
+then assign the desired result.
+With a comma:
+.Pp
+.Dl cur=$( sysrc -inr foo\ )
+.Dl sysrc foo="$cur${cur:+,}extra"
+.Pp
+The
+.Ql .=
+operator is equivalent to:
+.Pp
+.Dl cur=$( sysrc -inr foo\ )
+.Dl sysrc foo="$cur${cur:+ }extra"
.Sh ENVIRONMENT
The following environment variables are referenced by
.Nm :
@@ -448,6 +514,12 @@
from $cloned_interfaces
.Pq see Sx SUBTRACTING VALUES :
.Dl sysrc cloned_interfaces-=gif0
+.Pp
+Append
+.Dq -J 15
+to $cron_flags
+.Pq see Sx APPENDING TEXT :
+.Dl sysrc cron_flags.="-J 15"
.Ss Inline shell parameter expansion
Return $hostname up to, but not including, first
.Ql \&. :
diff --git a/usr.sbin/sysrc/tests/sysrc_test.sh b/usr.sbin/sysrc/tests/sysrc_test.sh
--- a/usr.sbin/sysrc/tests/sysrc_test.sh
+++ b/usr.sbin/sysrc/tests/sysrc_test.sh
@@ -434,12 +434,63 @@
atf_check -o inline:'test_flags="-J 16"\n' cat "${SYSRC_CONF}"
}
+atf_test_case strappend
+strappend_head()
+{
+ atf_set "descr" "String-append with .= inserts a space"
+}
+strappend_body()
+{
+ local msg
+
+ # NULL value: no leading space
+ atf_check -o inline:'cron_flags: -> -J 15\n' \
+ sysrc -f "${SYSRC_CONF}" 'cron_flags.=-J 15'
+ atf_check -o inline:'cron_flags="-J 15"\n' cat "${SYSRC_CONF}"
+
+ printf '%s\n' 'cron_flags="$cron_flags"' > "${SYSRC_CONF}"
+
+ # A space is inserted. The text is not scanned for a delimiter
+ msg='cron_flags: $cron_flags -> $cron_flags -J 15'
+ atf_check -o inline:"$msg\n" \
+ sysrc -f "${SYSRC_CONF}" 'cron_flags.=-J 15'
+ atf_check -o inline:'cron_flags="$cron_flags -J 15"\n' \
+ cat "${SYSRC_CONF}"
+
+ # A second append adds the text again, with another space
+ msg='cron_flags: $cron_flags -J 15 ->'
+ msg="$msg "'$cron_flags -J 15 -J 15'
+ atf_check -o inline:"$msg\n" \
+ sysrc -f "${SYSRC_CONF}" 'cron_flags.=-J 15'
+
+ # -c reports the result and does not write
+ printf '%s\n' 'cron_flags="$cron_flags"' > "${SYSRC_CONF}"
+ msg="${SYSRC_CONF}: cron_flags: would change from"
+ msg="$msg \`\$cron_flags' to \`\$cron_flags -J 15'"
+ atf_check -s exit:1 -o inline:"$msg\n" \
+ sysrc -f "${SYSRC_CONF}" -v -c 'cron_flags.=-J 15'
+ atf_check -o inline:'cron_flags="$cron_flags"\n' \
+ cat "${SYSRC_CONF}"
+
+ # A comma stays text. .= does not take it as a delimiter
+ printf '%s\n' 'foo="bar"' > "${SYSRC_CONF}"
+ atf_check -o inline:'foo: bar -> bar ,extra\n' \
+ sysrc -f "${SYSRC_CONF}" 'foo.=,extra'
+ atf_check -o inline:'foo="bar ,extra"\n' cat "${SYSRC_CONF}"
+
+ # += is still an exclusive list: -J is present, 15 is not
+ printf '%s\n' 'cron_flags="-J 10"' > "${SYSRC_CONF}"
+ atf_check -o inline:'cron_flags: -J 10 -> -J 10 15\n' \
+ sysrc -f "${SYSRC_CONF}" 'cron_flags+=-J 15'
+}
+
atf_init_test_cases()
{
atf_add_test_case check_variable
atf_add_test_case set_variable
atf_add_test_case remove_variable_x_flag
atf_add_test_case append_list
+ atf_add_test_case strappend
atf_add_test_case subtract_list
atf_add_test_case multiple_operations
atf_add_test_case a_flag
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 19, 5:11 PM (22 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41849280
Default Alt Text
D61659.1795108270.diff (7 KB)
Attached To
Mode
D61659: sysrc: Add .= operator for STRAPPEND
Attached
Detach File
Event Timeline