Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jun 2025 16:41:12 +0200
From:      Jilles Tjoelker <jilles@stack.nl>
To:        Hiroki Sato <hrs@freebsd.org>
Cc:        src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org
Subject:   Re: git: 7faddeb395b7 - main - rc: Fix scripts that need pathname expansion
Message-ID:  <aE7biEfYX1iJAivH@stack.nl>
In-Reply-To: <202506142026.55EKQeGM032225@gitrepo.freebsd.org>
References:  <202506142026.55EKQeGM032225@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Jun 14, 2025 at 08:26:40PM +0000, Hiroki Sato wrote:
> The branch main has been updated by hrs:

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

> commit 7faddeb395b7976b44393db24f48ec47040eff07
> Author:     Hiroki Sato <hrs@FreeBSD.org>
> AuthorDate: 2025-06-14 20:24:41 +0000
> Commit:     Hiroki Sato <hrs@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

> 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)

Like the comment says, `local -` already saves and restores `set`
options, so it does not make sense to do it again manually.

If you want to stop using `local -` in rc and use `_s=$(set +o)`, etc.,
please do so consistently.

>  	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
> +}
> +

This is convenient but it should be kept in mind that unlike direct
pathname expansion it will not handle correctly pathnames containing
spaces. A comment may be appropriate.

If you do not want to use `local -`, I would prefer `eval "$_s"` instead
of `eval $_s` since not using the quotes requests word splitting which
is not needed (although it should not break anything either).

-- 
Jilles Tjoelker



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?aE7biEfYX1iJAivH>