Skip to content

Commit

Permalink
vconsole: allow setting default keymap through build option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
YHNdnzj authored and bluca committed Feb 15, 2023
1 parent 0688bea commit f129d0e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions factory/templates/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions factory/templates/vconsole.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is the fallback vconsole configuration provided by systemd.

#KEYMAP={{ SYSTEMD_DEFAULT_KEYMAP }}
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 7 additions & 4 deletions src/vconsole/vconsole-setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions tmpfiles.d/etc.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit f129d0e

Please sign in to comment.