Skip to content

Commit

Permalink
fix(10i18n): stop leaking shell options
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Michal Hecko authored and johannbg committed Mar 9, 2022
1 parent 3385989 commit 3506476
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions modules.d/10i18n/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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".
#
Expand Down

0 comments on commit 3506476

Please sign in to comment.