d1a34d
From a6984b52a7194d2b4a0007af74659f3a5fd2c9ed Mon Sep 17 00:00:00 2001
d1a34d
From: Pavel Valena <pvalena@redhat.com>
d1a34d
Date: Fri, 25 Mar 2022 17:26:19 +0100
d1a34d
Subject: [PATCH] fix(10i18n): stop leaking shell options
d1a34d
d1a34d
Avoid using shell options in findkeymap, instead of using a wrapper[*]
d1a34d
to restore the previous options. Using mapfile and find to generate the list
d1a34d
of files also has the benefit of being more readable in this case.
d1a34d
d1a34d
[*] Reverted commit 35064768ebf14d3ec6bf3f7df52580fb4920ea3d
d1a34d
Original issue description from Michal Hecko <mhecko@redhat.com>:
d1a34d
d1a34d
The findkeymap function manipulates the shell options and relies on
d1a34d
restoring them using the trap. However, as the function might be called
d1a34d
recursively, each recursive invocation changes the signal handler to its
d1a34d
own. As the recursion is entered with shell options already modified,
d1a34d
the changed trap handler is replaced with restoration to the modified
d1a34d
shell options, not the original ones.
d1a34d
d1a34d
Resolves: #2047654
d1a34d
---
d1a34d
 modules.d/10i18n/module-setup.sh | 9 ++++-----
d1a34d
 1 file changed, 4 insertions(+), 5 deletions(-)
d1a34d
d1a34d
diff --git a/modules.d/10i18n/module-setup.sh b/modules.d/10i18n/module-setup.sh
d1a34d
index f25026fb..35bda36f 100755
d1a34d
--- a/modules.d/10i18n/module-setup.sh
d1a34d
+++ b/modules.d/10i18n/module-setup.sh
d1a34d
@@ -31,10 +31,6 @@ install() {
d1a34d
     VCONFIG_CONF="/etc/vconsole.conf"
d1a34d
 
d1a34d
     findkeymap() {
d1a34d
-        # shellcheck disable=SC2064
d1a34d
-        trap "$(shopt -p nullglob globstar)" RETURN
d1a34d
-        shopt -q -s nullglob globstar
d1a34d
-
d1a34d
         local -a MAPS
d1a34d
         local MAPNAME
d1a34d
         local INCLUDES
d1a34d
@@ -46,7 +42,10 @@ install() {
d1a34d
             MAPS=("$1")
d1a34d
         else
d1a34d
             MAPNAME=${1%.map*}
d1a34d
-            MAPS=("$dracutsysrootdir""${kbddir}"/keymaps/**/"${MAPNAME}"{,.map{,.*}})
d1a34d
+
d1a34d
+            mapfile -t -d '' MAPS < <(
d1a34d
+                find "${dracutsysrootdir}${kbddir}"/keymaps/ -type f \( -name "${MAPNAME}" -o -name "${MAPNAME}.map*" \) -print0
d1a34d
+            )
d1a34d
         fi
d1a34d
 
d1a34d
         for MAP in "${MAPS[@]}"; do
d1a34d