Skip to content

Commit 3506476

Browse files
Michal Heckojohannbg
Michal Hecko
authored andcommitted
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.
1 parent 3385989 commit 3506476

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Diff for: modules.d/10i18n/module-setup.sh

+11-6
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ install() {
3030
I18N_CONF="/etc/locale.conf"
3131
VCONFIG_CONF="/etc/vconsole.conf"
3232

33-
findkeymap() {
34-
# shellcheck disable=SC2064
35-
trap "$(shopt -p nullglob globstar)" RETURN
36-
shopt -q -s nullglob globstar
37-
33+
_findkeymap() {
3834
local -a MAPS
3935
local MAPNAME
4036
local INCLUDES
@@ -66,12 +62,21 @@ install() {
6662
for INCL in "${INCLUDES[@]}"; do
6763
for FN in "$dracutsysrootdir""${kbddir}"/keymaps/**/"$INCL"*; do
6864
[[ -f $FN ]] || continue
69-
[[ -v KEYMAPS["$FN"] ]] || findkeymap "$FN"
65+
[[ -v KEYMAPS["$FN"] ]] || _findkeymap "$FN"
7066
done
7167
done
7268
done
7369
}
7470
71+
# Wrapper around the recursive _findkeymap making sure the shell
72+
# options are restored correctly
73+
findkeymap() {
74+
# shellcheck disable=SC2064
75+
trap "$(shopt -p nullglob globstar)" RETURN
76+
shopt -q -s nullglob globstar
77+
_findkeymap "$@"
78+
}
79+
7580
# Function gathers variables from distributed files among the tree, maps to
7681
# specified names and prints the result in format "new-name=value".
7782
#

0 commit comments

Comments
 (0)