From: Michal Hecko Date: Mon, 21 Feb 2022 09:59:27 +0000 (+0100) Subject: fix(10i18n): stop leaking shell options X-Git-Tag: 057~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35064768ebf14d3ec6bf3f7df52580fb4920ea3d;p=thirdparty%2Fdracut.git fix(10i18n): stop leaking shell options The findkeymap function manipulates the shell options and relies on restoring them using the trap. However, as the function might be called recursively, each recursive invocation changes the signal handler to its own. As the recursion is entered with shell options already modified, the changed trap handler is replaced with restoration to the modified shell options, not the original ones. This patch wraps the findkeymap function so that the shellopts are manipulated and restored outside the recursion. --- diff --git a/modules.d/10i18n/module-setup.sh b/modules.d/10i18n/module-setup.sh index f25026fb8..91c189e82 100755 --- a/modules.d/10i18n/module-setup.sh +++ b/modules.d/10i18n/module-setup.sh @@ -30,11 +30,7 @@ install() { I18N_CONF="/etc/locale.conf" VCONFIG_CONF="/etc/vconsole.conf" - findkeymap() { - # shellcheck disable=SC2064 - trap "$(shopt -p nullglob globstar)" RETURN - shopt -q -s nullglob globstar - + _findkeymap() { local -a MAPS local MAPNAME local INCLUDES @@ -66,12 +62,21 @@ install() { for INCL in "${INCLUDES[@]}"; do for FN in "$dracutsysrootdir""${kbddir}"/keymaps/**/"$INCL"*; do [[ -f $FN ]] || continue - [[ -v KEYMAPS["$FN"] ]] || findkeymap "$FN" + [[ -v KEYMAPS["$FN"] ]] || _findkeymap "$FN" done done done } + # Wrapper around the recursive _findkeymap making sure the shell + # options are restored correctly + findkeymap() { + # shellcheck disable=SC2064 + trap "$(shopt -p nullglob globstar)" RETURN + shopt -q -s nullglob globstar + _findkeymap "$@" + } + # Function gathers variables from distributed files among the tree, maps to # specified names and prints the result in format "new-name=value". #