]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
vconsole-util: move code to read EFI keyboard layout into generic code
authorLennart Poettering <lennart@amutable.com>
Tue, 19 May 2026 12:51:41 +0000 (14:51 +0200)
committerLennart Poettering <lennart@amutable.com>
Wed, 20 May 2026 14:34:21 +0000 (16:34 +0200)
src/shared/vconsole-util.c
src/shared/vconsole-util.h
src/vconsole/vconsole-setup.c

index aa156f4736fc6a4ab44ced1a151420fd3ed22f44..9e56ce823df42cc369da4286ece9a042f034f339 100644 (file)
@@ -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;
 
index 3d52ec9866ce8789c276c279675bbc4b0b2263e3..416eb86eb54b971531326954fbeb752ceb9ae1a5 100644 (file)
@@ -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);
index c1bf2b0f4f5d9649e9e4c528e3b8a00bcc629c3e..f8c5dffd1eea9b64cd2af84f4cb8719429d52fbf 100644 (file)
@@ -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;
         }