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.
This commit is contained in:
Mike Yuan 2023-01-18 01:21:59 +08:00 committed by Luca Boccassi
parent 0688bea163
commit f129d0e77c
6 changed files with 24 additions and 4 deletions

View 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)

View File

@ -0,0 +1,3 @@
# This is the fallback vconsole configuration provided by systemd.
#KEYMAP={{ SYSTEMD_DEFAULT_KEYMAP }}

View 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)

View 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',

View 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);

View 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 %}