diff --git a/src/shared/vconsole-util.c b/src/shared/vconsole-util.c index aa156f4736..9e56ce823d 100644 --- a/src/shared/vconsole-util.c +++ b/src/shared/vconsole-util.c @@ -4,6 +4,7 @@ #include #include "alloc-util.h" +#include "efivars.h" #include "env-util.h" #include "extract-word.h" #include "fd-util.h" @@ -655,6 +656,32 @@ int find_vconsole_keymap_for_bcp47(const char *tag, char **ret) { return 1; } +int vconsole_keymap_from_efi(char **ret) { + int r; + + assert(ret); + + if (!is_efi_boot()) { + *ret = NULL; + return 0; + } + + _cleanup_free_ char *tag = NULL; + r = efi_get_variable_string(EFI_LOADER_VARIABLE_STR("LoaderKeyboardLayout"), &tag); + if (r == -ENOENT) { + *ret = NULL; + return 0; + } + if (r < 0) + return log_debug_errno(r, "Failed to read LoaderKeyboardLayout EFI variable: %m"); + + r = find_vconsole_keymap_for_bcp47(tag, ret); + if (r < 0) + return log_debug_errno(r, "Failed to look up vconsole keymap for firmware tag '%s': %m", tag); + + return r; +} + int vconsole_serialize(const VCContext *vc, const X11Context *xc, char ***env) { int r; diff --git a/src/shared/vconsole-util.h b/src/shared/vconsole-util.h index 3d52ec9866..416eb86eb5 100644 --- a/src/shared/vconsole-util.h +++ b/src/shared/vconsole-util.h @@ -40,5 +40,6 @@ int vconsole_convert_to_x11(const VCContext *vc, X11VerifyCallback verify, X11Co int x11_convert_to_vconsole(const X11Context *xc, VCContext *ret); int find_vconsole_keymap_for_bcp47(const char *tag, char **ret); +int vconsole_keymap_from_efi(char **ret); int vconsole_serialize(const VCContext *vc, const X11Context *xc, char ***env); diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index c1bf2b0f4f..f8c5dffd1e 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -15,7 +15,6 @@ #include "alloc-util.h" #include "creds-util.h" -#include "efivars.h" #include "env-file.h" #include "errno-util.h" #include "fd-util.h" @@ -76,25 +75,15 @@ static void context_merge_config( static int context_read_efi(Context *c) { _cleanup_(context_done) Context v = {}; - _cleanup_free_ char *tag = NULL; int r; assert(c); - if (!is_efi_boot()) - return 0; - - r = efi_get_variable_string(EFI_LOADER_VARIABLE_STR("LoaderKeyboardLayout"), &tag); - if (r == -ENOENT) - return 0; + r = vconsole_keymap_from_efi(&v.keymap); if (r < 0) - return log_debug_errno(r, "Failed to read LoaderKeyboardLayout EFI variable, ignoring: %m"); - - r = find_vconsole_keymap_for_bcp47(tag, &v.keymap); - if (r < 0) - return log_debug_errno(r, "Failed to look up vconsole keymap for firmware tag '%s', ignoring: %m", tag); + return r; if (r == 0) { - log_debug("No vconsole keymap matches firmware-provided keyboard layout '%s', ignoring.", tag); + log_debug("No vconsole keymap matches firmware-provided keyboard layout, ignoring."); return 0; }