git: 09711ccb09f4 - main - Remove source_rc_confs, inlined from defaults/rc.conf
Date: Tue, 15 Sep 2026 20:53:12 UTC
The branch main has been updated by dteske:
URL: https://cgit.FreeBSD.org/src/commit/?id=09711ccb09f482fd345b2b640dbbeb66de535041
commit 09711ccb09f482fd345b2b640dbbeb66de535041
Author: Devin Teske <dteske@FreeBSD.org>
AuthorDate: 2026-09-15 20:50:20 +0000
Commit: Devin Teske <dteske@FreeBSD.org>
CommitDate: 2026-09-15 20:50:20 +0000
Remove source_rc_confs, inlined from defaults/rc.conf
Inlining source_rc_confs broke sysrc_test:A_flag
While here, switch to SPDX, bump version/copyrights, fixup comments.
Prevent common function override when bsdconfig includes new
sysrc.subr that contains inlined commons. Fix non-unique duplicate
header variable incorrectly shared between bsdconfig's sysrc.subr
include and new sysrc.subr include.
Harden RC_DEFAULTS parameter expansion from DoS-via-glob (SC2223).
Move pgm to the correct location to not override bsdconfig's pgm.
Drop _SYSRC_JAILED=1 that is no-longer needed. Drop i18n from
jail_depend now that messages are inlined to subr.
Reported by: siva
Fixes: eaeb5f29bc6f sysrc: make independant from bsdconfig(8)
---
usr.sbin/bsdconfig/share/sysrc.subr | 13 ++---
usr.sbin/sysrc/sysrc | 62 ++++-----------------
usr.sbin/sysrc/sysrc.subr | 108 ++++++++++--------------------------
3 files changed, 45 insertions(+), 138 deletions(-)
diff --git a/usr.sbin/bsdconfig/share/sysrc.subr b/usr.sbin/bsdconfig/share/sysrc.subr
index eee489f4cc50..02bc96fd4fee 100644
--- a/usr.sbin/bsdconfig/share/sysrc.subr
+++ b/usr.sbin/bsdconfig/share/sysrc.subr
@@ -1,6 +1,6 @@
-if [ ! "$_SYSRC_SUBR" ]; then _SYSRC_SUBR=1
+if [ ! "$_BSDCONFIG_SYSRC_SUBR" ]; then _BSDCONFIG_SYSRC_SUBR=1
#
-# Copyright (c) 2006-2015 Devin Teske
+# Copyright (c) 2006-2026 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,6 +24,7 @@ if [ ! "$_SYSRC_SUBR" ]; then _SYSRC_SUBR=1
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
+############################################################ INFORMATION
#
# Compatibility shim: sources the canonical sysrc.subr from /usr/share/sysrc/
# and loads bsdconfig-specific i18n messages afterward.
@@ -36,13 +37,11 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
f_include /usr/share/sysrc/sysrc.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
-if [ ! "$_SYSRC_JAILED" ]; then
- f_dprintf "%s: loading includes..." sysrc.subr
- f_include_lang $BSDCFG_LIBE/include/messages.subr
-fi
+f_dprintf "%s: loading includes..." sysrc.subr
+f_include_lang $BSDCFG_LIBE/include/messages.subr
############################################################ MAIN
f_dprintf "%s: Successfully loaded." sysrc.subr
-fi # ! $_SYSRC_SUBR
+fi # ! $_BSDCONFIG_SYSRC_SUBR
diff --git a/usr.sbin/sysrc/sysrc b/usr.sbin/sysrc/sysrc
index bd3faeac8ed3..21a17a7b761b 100644
--- a/usr.sbin/sysrc/sysrc
+++ b/usr.sbin/sysrc/sysrc
@@ -1,29 +1,8 @@
#!/bin/sh
-#-
-# Copyright (c) 2010-2018 Devin Teske
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2010-2026 Devin Teske
#
############################################################ INCLUDES
@@ -32,10 +11,12 @@ SYSRC_SHARE="/usr/share/sysrc"
############################################################ GLOBALS
+pgm="${0##*/}" # Program basename
+
#
# Version information
#
-SYSRC_VERSION="7.2 Jun-16,2018"
+SYSRC_VERSION="7.3 Sep-15,2026"
#
# Options
@@ -171,35 +152,14 @@ help()
# jail_depend
#
-# Dump dependencies such as language-file variables and include files to stdout
-# to be piped-into sh(1) running via jexec(8)/chroot(8). As a security measure,
-# this prevents existing language files and library files from being loaded in
-# the jail. This also relaxes the requirement to have these files in every jail
-# before sysrc can be used on said jail.
+# Dump dependencies such as include files to stdout to be piped-into sh(1)
+# running via jexec(8)/chroot(8). As a security measure, this prevents existing
+# library files from being loaded in the jail. This also relaxes the
+# requirement to have these files in every jail before sysrc can be used on
+# said jail.
#
jail_depend()
{
- #
- # Indicate that we are jailed
- #
- echo export _SYSRC_JAILED=1
-
- #
- # Print i18n language variables (their current values are sanitized
- # and re-printed for interpretation so that the i18n language files
- # do not need to exist within the jail).
- #
- local var val
- for var in \
- msg_cannot_create_permission_denied \
- msg_permission_denied \
- msg_previous_syntax_errors \
- ; do
- val=$( eval echo \"\$$var\" |
- awk '{ gsub(/'\''/, "'\''\\'\'\''"); print }' )
- echo $var="'$val'"
- done
-
#
# Print include dependencies
#
diff --git a/usr.sbin/sysrc/sysrc.subr b/usr.sbin/sysrc/sysrc.subr
index 63c92843c672..0396628c929f 100644
--- a/usr.sbin/sysrc/sysrc.subr
+++ b/usr.sbin/sysrc/sysrc.subr
@@ -1,29 +1,10 @@
if [ ! "$_SYSRC_SUBR" ]; then _SYSRC_SUBR=1
#
-# Copyright (c) 2006-2015 Devin Teske
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
+# SPDX-License-Identifier: BSD-2-Clause
#
+# Copyright (c) 2006-2026 Devin Teske
+#
+############################################################ INFORMATION
#
# This file was split-out of bsdconfig(8) and is now self-contained, and is
# no longer dependent on bsdconfig(8) or any of its libraries.
@@ -33,7 +14,7 @@ if [ ! "$_SYSRC_SUBR" ]; then _SYSRC_SUBR=1
#
# Standard pathnames (inherit values from shell if available)
#
-: ${RC_DEFAULTS:="/etc/defaults/rc.conf"}
+: "${RC_DEFAULTS:=/etc/defaults/rc.conf}"
############################################################ GLOBALS
@@ -44,12 +25,7 @@ SUCCESS=0
FAILURE=1
#
-# Program name (derived from the running script)
-#
-pgm="${0##*/}"
-
-#
-# Error messages.
+# Error messages
#
msg_cannot_create_permission_denied="%s: cannot create %s: Permission denied"
msg_permission_denied="%s: %s: Permission denied"
@@ -68,24 +44,28 @@ VALID_VARNAME_CHARS="0-9ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"
############################################################ FUNCTIONS
-# f_err $format [$arguments ...]
-#
-# Print a message to stderr (fd=2).
-#
-f_err()
-{
- printf "$@" >&2
-}
-
# f_have $anything ...
#
# A wrapper to the `type' built-in. Returns true if argument is a valid shell
# built-in, keyword, or externally-tracked binary, otherwise false.
#
+if ! type f_have > /dev/null 2>&1; then
f_have()
{
type "$@" > /dev/null 2>&1
}
+fi
+
+# f_err $format [$arguments ...]
+#
+# Print a message to stderr (fd=2).
+#
+if ! f_have f_err; then
+f_err()
+{
+ printf "$@" >&2
+}
+fi
# setvar $var_to_set [$value]
#
@@ -125,8 +105,10 @@ fi
# Returns error status if the requested variable ($var_to_get) is not set.
#
# If $var_to_set is missing or NULL, the value of $var_to_get is printed to
-# standard output for capturing in a sub-shell.
+# standard output for capturing in a sub-shell (which is less-recommended
+# because of performance degredation; for example, when called in a loop).
#
+if ! f_have f_getvar; then
f_getvar()
{
local __var_to_get="$1" __var_to_set="$2"
@@ -137,21 +119,22 @@ f_getvar()
[ "$__var_to_set" ] || { [ "$value" ] && echo "$value"; }
return $__retval
}
+fi
-# f_eval_catch [ -d ] [ -e ] [ -k $var_to_set ] $funcname $utility \
+# f_eval_catch [-de] [-k $var_to_set] $funcname $utility \
# $printf_format [$printf_args ...]
#
# Evaluate the printf-rendered command line and capture its output. The return
# status of the command is preserved. If `-k' is given, output is stored in
# $var_to_set. If `-e' is given, output is echoed to stderr on failure.
#
+if ! f_have f_eval_catch; then
f_eval_catch()
{
local OPTIND OPTARG __flag __show_err= __var_to_set=
while getopts "dek:" __flag > /dev/null; do
case "$__flag" in
- d) : # no-op: always non-interactive here
- ;;
+ d) : ;; # no-op: always non-interactive here
e) __show_err=1 ;;
k) __var_to_set="$OPTARG" ;;
esac
@@ -170,44 +153,9 @@ f_eval_catch()
[ "$__var_to_set" ] && setvar "$__var_to_set" "$__output"
return $__retval
}
+fi
-# source_rc_confs
-#
-# Source the rc.conf(5) override files (as defined in rc.conf(5)), preserving
-# the semantics used by /etc/rc.* at boot-time.
-#
-source_rc_confs()
-{
- local i sourced_files
- for i in ${rc_conf_files}; do
- case ${sourced_files} in
- *:$i:*)
- ;;
- *)
- sourced_files="${sourced_files}:$i:"
- if [ -r $i ]; then
- . $i
- fi
- ;;
- esac
- done
- # Re-do process to pick up [possibly] redefined $rc_conf_files
- for i in ${rc_conf_files}; do
- case ${sourced_files} in
- *:$i:*)
- ;;
- *)
- sourced_files="${sourced_files}:$i:"
- if [ -r $i ]; then
- . $i
- fi
- ;;
- esac
- done
-}
-
-
-# f_clean_env [ --except $varname ... ]
+# f_clean_env [--except $varname ...]
#
# Unset all environment variables in the current scope. An optional list of
# arguments can be passed, indicating which variables to avoid unsetting; the