]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
vconsole: allow setting default keymap through build option
authorMike Yuan <me@yhndnzj.com>
Tue, 17 Jan 2023 17:21:59 +0000 (01:21 +0800)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 15 Feb 2023 20:00:51 +0000 (20:00 +0000)
Allow defining the default keymap to be used by
vconsole-setup through a build option. A template
vconsole.conf also gets populated by tmpfiles if
it doesn't exist.

factory/templates/meson.build
factory/templates/vconsole.conf.in [new file with mode: 0644]
meson.build
meson_options.txt
src/vconsole/vconsole-setup.c
tmpfiles.d/etc.conf.in

index ece2c644ff21faac690feb71521e7d6d777a05eb..a3ba7b166ffe031bd365663d721042af3b56e7a9 100644 (file)
@@ -9,3 +9,11 @@ custom_target(
         command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'],
         install : true,
         install_dir : factory_etc_dir)
+
+custom_target(
+        'vconsole.conf',
+        input : 'vconsole.conf.in',
+        output : 'vconsole.conf',
+        command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'],
+        install : true,
+        install_dir : factory_etc_dir)
diff --git a/factory/templates/vconsole.conf.in b/factory/templates/vconsole.conf.in
new file mode 100644 (file)
index 0000000..f682487
--- /dev/null
@@ -0,0 +1,3 @@
+# This is the fallback vconsole configuration provided by systemd.
+
+#KEYMAP={{ SYSTEMD_DEFAULT_KEYMAP }}
index bfc86857d62663d138d192a7a15ea57c0c2ea0e8..319246c6393eb3144454ca9cd7d20e88898b83db 100644 (file)
@@ -985,6 +985,9 @@ conf.set_quoted('SYSTEMD_DEFAULT_LOCALE', default_locale)
 nspawn_locale = get_option('nspawn-locale')
 conf.set_quoted('SYSTEMD_NSPAWN_LOCALE', nspawn_locale)
 
+default_keymap = get_option('default-keymap')
+conf.set_quoted('SYSTEMD_DEFAULT_KEYMAP', default_keymap)
+
 localegen_path = get_option('localegen-path')
 if localegen_path != ''
         conf.set_quoted('LOCALEGEN_PATH', localegen_path)
index 17c88e23a1d3bee5d4743ee88fb8d02de8505810..f59c3997951d37ae92b5ba1a25d35a6d70f9b802 100644 (file)
@@ -312,6 +312,8 @@ option('default-locale', type : 'string', value : 'C.UTF-8',
        description : 'default locale used when /etc/locale.conf does not exist')
 option('nspawn-locale', type : 'string', value : 'C.UTF-8',
        description : 'default locale used by systemd-nspawn when executing commands in a container')
+option('default-keymap', type : 'string', value : 'us',
+       description : 'default keymap used when populating /etc/vconsole.conf')
 option('localegen-path', type : 'string', value : '',
        description : 'absolute path to the locale-gen binary in case the system is using locale-gen')
 option('service-watchdog', type : 'string', value : '3min',
index 7d3e9db73f877eea70ccbb6136d00555c729e94a..9a09b0d5160a50aa915c694e60dd8a163f325a55 100644 (file)
@@ -415,9 +415,10 @@ static int verify_source_vc(char **ret_path, const char *src_vc) {
 int main(int argc, char **argv) {
         _cleanup_free_ char
                 *vc = NULL,
-                *vc_keymap = NULL, *vc_keymap_toggle = NULL,
+                *vc_keymap_alloc = NULL, *vc_keymap_toggle = NULL,
                 *vc_font = NULL, *vc_font_map = NULL, *vc_font_unimap = NULL;
         _cleanup_close_ int fd = -EBADF;
+        const char *vc_keymap;
         bool utf8, keyboard_ok;
         unsigned idx = 0;
         int r;
@@ -437,7 +438,7 @@ int main(int argc, char **argv) {
 
         /* Load data from credentials (lowest priority) */
         r = read_credential_strings_many(
-                        "vconsole.keymap", &vc_keymap,
+                        "vconsole.keymap", &vc_keymap_alloc,
                         "vconsole.keymap_toggle", &vc_keymap_toggle,
                         "vconsole.font", &vc_font,
                         "vconsole.font_map", &vc_font_map,
@@ -447,7 +448,7 @@ int main(int argc, char **argv) {
 
         /* Load data from configuration file (middle priority) */
         r = parse_env_file(NULL, "/etc/vconsole.conf",
-                           "KEYMAP", &vc_keymap,
+                           "KEYMAP", &vc_keymap_alloc,
                            "KEYMAP_TOGGLE", &vc_keymap_toggle,
                            "FONT", &vc_font,
                            "FONT_MAP", &vc_font_map,
@@ -458,7 +459,7 @@ int main(int argc, char **argv) {
         /* Let the kernel command line override /etc/vconsole.conf (highest priority) */
         r = proc_cmdline_get_key_many(
                         PROC_CMDLINE_STRIP_RD_PREFIX,
-                        "vconsole.keymap", &vc_keymap,
+                        "vconsole.keymap", &vc_keymap_alloc,
                         "vconsole.keymap_toggle", &vc_keymap_toggle,
                         "vconsole.font", &vc_font,
                         "vconsole.font_map", &vc_font_map,
@@ -470,6 +471,8 @@ int main(int argc, char **argv) {
         if (r < 0 && r != -ENOENT)
                 log_warning_errno(r, "Failed to read /proc/cmdline, ignoring: %m");
 
+        vc_keymap = isempty(vc_keymap_alloc) ? SYSTEMD_DEFAULT_KEYMAP : vc_keymap_alloc;
+
         (void) toggle_utf8_sysfs(utf8);
         (void) toggle_utf8_vc(vc, fd, utf8);
 
index 2fdd498da58575e9d50f17dd177335ade0720007..e54d3b18994a94a31c8763d9e1f530e91dffee77 100644 (file)
@@ -14,6 +14,7 @@ t /etc/mtab - - - - security.SMACK64=_
 {% endif %}
 C! /etc/locale.conf - - - -
 C! /etc/nsswitch.conf - - - -
+C! /etc/vconsole.conf - - - -
 {% if HAVE_PAM %}
 C! /etc/pam.d - - - -
 {% endif %}