vconsole-util: move code to read EFI keyboard layout into generic code
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user