From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6763715800F for ; Tue, 7 Feb 2023 01:08:55 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6F9F3E0870; Tue, 7 Feb 2023 01:08:54 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 57115E0870 for ; Tue, 7 Feb 2023 01:08:54 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3B22E340A85 for ; Tue, 7 Feb 2023 01:08:53 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 575E785B for ; Tue, 7 Feb 2023 01:08:51 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1675731751.2a7399e84b2fcb37e9f2e9ec9f7ecd9c60111f3b.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 2a7399e84b2fcb37e9f2e9ec9f7ecd9c60111f3b X-VCS-Branch: master Date: Tue, 7 Feb 2023 01:08:51 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: ab6c897f-1bde-45af-9d2c-680976f8fcdb X-Archives-Hash: 33edd9042be6cc2941e06ef2cd5a14b7 commit: 2a7399e84b2fcb37e9f2e9ec9f7ecd9c60111f3b Author: Kerin Millar plushkava net> AuthorDate: Tue Feb 7 00:39:59 2023 +0000 Commit: Sam James gentoo 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 plushkava.net> Bug: https://bugs.gentoo.org/886017 Signed-off-by: Sam James 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