From 35064768ebf14d3ec6bf3f7df52580fb4920ea3d Mon Sep 17 00:00:00 2001 From: Michal Hecko Date: Mon, 21 Feb 2022 10:59:27 +0100 Subject: [PATCH] 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. --- modules.d/10i18n/module-setup.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/modules.d/10i18n/module-setup.sh b/modules.d/10i18n/module-setup.sh index f25026fb80..91c189e825 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". #