commit: 2a7399e84b2fcb37e9f2e9ec9f7ecd9c60111f3b Author: Kerin Millar <kfm <AT> plushkava <DOT> net> AuthorDate: Tue Feb 7 00:39:59 2023 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Tue Feb 7 01:02:31 2023 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=2a7399e8
Re-implement get_bootparam as pure sh, eliminating the gawk dependency The current implementation of get_bootparam() specifically invokes gawk and has some deficiencies, such as failing to inhibit pathname expansion and not breaking the loop once a match has been made. In fact, the problem can be solved using sh(1) alone, and the revised function does precisely that. Note that the definition of the function is now the kind of compound command that incurs a subshell. Hence, one subshell is incurred for the entire routine and there is no compelling reason to use the (non-standard) local keyword, nor be concerned with the consequences of disabling pathname expansion. Signed-off-by: Kerin Millar <kfm <AT> plushkava.net> Bug: https://bugs.gentoo.org/886017 Signed-off-by: Sam James <sam <AT> gentoo.org> functions.sh | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/functions.sh b/functions.sh index 0a5d38e..08950b8 100644 --- a/functions.sh +++ b/functions.sh @@ -336,33 +336,28 @@ veoutdent() # EXAMPLE: if get_bootparam "nodevfs" ; then .... # get_bootparam() -{ - local x copt params retval=1 - - [ ! -r /proc/cmdline ] && return 1 - - read copts < /proc/cmdline - for copt in $copts ; do - if [ "${copt%=*}" = "gentoo" ] ; then - params=$(gawk -v PARAMS="${copt##*=}" ' - BEGIN { - split(PARAMS, nodes, ",") - for (x in nodes) - print nodes[x] - }') - - # Parse gentoo option - for x in ${params} ; do - if [ "${x}" = "$1" ] ; then -# echo "YES" - retval=0 - fi - done +( + # Gentoo cmdline parameters are comma-delimited, so a search + # string containing a comma must not be allowed to match. + # Similarly, the empty string must not be allowed to match. + case $1 in ''|*,*) return 1 ;; esac + + read -r cmdline < /proc/cmdline || return + + # Disable pathname expansion. The definition of this function + # is a compound command that incurs a subshell. Therefore, the + # prior state of the option does not need to be recalled. + set -f + for opt in ${cmdline}; do + gentoo_opt=${opt#gentoo=} + if [ "${opt}" != "${gentoo_opt}" ]; then + case ,${gentoo_opt}, in + *,"$1",*) return 0 + esac fi done - - return ${retval} -} + return 1 +) # # return 0 if any of the files/dirs are newer than
