The branch main has been updated by hrs:

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

commit 7faddeb395b7976b44393db24f48ec47040eff07
Author:     Hiroki Sato <h...@freebsd.org>
AuthorDate: 2025-06-14 20:24:41 +0000
Commit:     Hiroki Sato <h...@freebsd.org>
CommitDate: 2025-06-14 20:24:41 +0000

    rc: Fix scripts that need pathname expansion
    
    Reported by:    Kenneth Raplee
    Differential Revision:  https://reviews.freebsd.org/D45855
---
 libexec/rc/rc.d/moused  |  2 +-
 libexec/rc/rc.d/syscons |  4 ++--
 libexec/rc/rc.subr      | 24 ++++++++++++++++++++----
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/libexec/rc/rc.d/moused b/libexec/rc/rc.d/moused
index 6f1b95af0f0a..9bb1a5cedc31 100755
--- a/libexec/rc/rc.d/moused
+++ b/libexec/rc/rc.d/moused
@@ -69,7 +69,7 @@ moused_start()
                ;;
        esac
 
-       for ttyv in /dev/ttyv* ; do
+       for ttyv in $(expandpath "/dev/ttyv*"); do
                vidcontrol < ${ttyv} ${mousechar_arg} -m on
        done
 }
diff --git a/libexec/rc/rc.d/syscons b/libexec/rc/rc.d/syscons
index 325628a83d8c..7ad9b720e454 100755
--- a/libexec/rc/rc.d/syscons
+++ b/libexec/rc/rc.d/syscons
@@ -237,7 +237,7 @@ syscons_configure_keyboard()
        if [ -n "${allscreens_kbdflags}" ]; then
                sc_init
                echo -n ' allscreens_kbd'
-               for ttyv in /dev/ttyv*; do
+               for ttyv in $(expandpath "/dev/ttyv*"); do
                        kbdcontrol ${allscreens_kbdflags} < ${ttyv} > ${ttyv} 
2>&1
                done
        fi
@@ -381,7 +381,7 @@ syscons_start()
        if [ -n "${allscreens_flags}" ]; then
                sc_init
                echo -n ' allscreens'
-               for ttyv in /dev/ttyv*; do
+               for ttyv in $(expandpath "/dev/ttyv*"); do
                        vidcontrol ${allscreens_flags} < ${ttyv} > ${ttyv} 2>&1
                done
        fi
diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr
index 359eebd1d342..d760b75a15a3 100644
--- a/libexec/rc/rc.subr
+++ b/libexec/rc/rc.subr
@@ -223,10 +223,11 @@ rc_trace()
 list_vars()
 {
        # Localize 'set' option below.
-       local -
+       local - _s
        local IFS=$'\n' line varname
 
-       # Disable path expansion in unquoted 'for' parameters below.
+       # Disable path expansion temporarily in unquoted 'for' parameters below.
+       _s=$(set +o)
        set -o noglob
 
        for line in $(set); do
@@ -241,6 +242,7 @@ list_vars()
                        ;;
                esac
        done
+       eval $_s
 }
 
 # set_rcvar [var] [defval] [desc]
@@ -292,6 +294,19 @@ set_rcvar_obsolete()
        eval ${_var}_obsolete_msg=\"$*\"
 }
 
+# expandpath str
+#      Apply pathname expansion to str.
+#
+expandpath()
+{
+       local _s
+
+       _s=$(set +o)
+       set +o noglob
+       echo $1
+       eval $_s
+}
+
 #
 # force_depend script [rcvar]
 #      Force a service to start. Intended for use by services
@@ -1783,18 +1798,19 @@ _run_rc_setup()
 
 _run_rc_doit()
 {
-       local _m
+       local _m _s
 
        debug "run_rc_command: doit: $*"
        _m=$(umask)
        ${_umask:+umask ${_umask}}
 
        # Disable pathname expansion temporarily for run_rc_command. 
+       _s=$(set +o)
        set -o noglob
        eval "$@"
-       set +o noglob
        _return=$?
        umask ${_m}
+       eval $_s
 
        # If command failed and force isn't set, request exit.
        if [ $_return -ne 0 ] && [ -z "$rc_force" ]; then

Reply via email to