diff options
author | Mike Yuan <me@yhndnzj.com> | 2023-01-18 01:21:59 +0800 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2023-02-15 20:00:51 +0000 |
commit | f129d0e77c4c9a0e12ae38cd241cd49846844a80 (patch) | |
tree | 6518a9c10e5f4697ac1ab47e668330bcfa780ba9 | |
parent | 0688bea1631c9ddb83cbfadfe7e0bb66ffc3e17a (diff) | |
download | systemd-f129d0e77c4c9a0e12ae38cd241cd49846844a80.tar.gz |
vconsole: allow setting default keymap through build option
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.
-rw-r--r-- | factory/templates/meson.build | 8 | ||||
-rw-r--r-- | factory/templates/vconsole.conf.in | 3 | ||||
-rw-r--r-- | meson.build | 3 | ||||
-rw-r--r-- | meson_options.txt | 2 | ||||
-rw-r--r-- | src/vconsole/vconsole-setup.c | 11 | ||||
-rw-r--r-- | tmpfiles.d/etc.conf.in | 1 |
6 files changed, 24 insertions, 4 deletions
diff --git a/factory/templates/meson.build b/factory/templates/meson.build index ece2c644ff..a3ba7b166f 100644 --- a/factory/templates/meson.build +++ b/factory/templates/meson.build @@ -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 index 0000000000..f682487695 --- /dev/null +++ b/factory/templates/vconsole.conf.in @@ -0,0 +1,3 @@ +# This is the fallback vconsole configuration provided by systemd. + +#KEYMAP={{ SYSTEMD_DEFAULT_KEYMAP }} diff --git a/meson.build b/meson.build index bfc86857d6..319246c639 100644 --- a/meson.build +++ b/meson.build @@ -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) diff --git a/meson_options.txt b/meson_options.txt index 17c88e23a1..f59c399795 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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', diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index 7d3e9db73f..9a09b0d516 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -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); diff --git a/tmpfiles.d/etc.conf.in b/tmpfiles.d/etc.conf.in index 2fdd498da5..e54d3b1899 100644 --- a/tmpfiles.d/etc.conf.in +++ b/tmpfiles.d/etc.conf.in @@ -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 %} |