Closes #24228.
Replaces #25412.
assert(c);
x11_context_clear(&c->x11_from_xorg);
+ x11_context_clear(&c->x11_from_vc);
}
static void context_clear_vconsole(Context *c) {
static X11Context *context_get_x11_context(Context *c) {
assert(c);
+ if (!x11_context_isempty(&c->x11_from_vc))
+ return &c->x11_from_vc;
+
if (!x11_context_isempty(&c->x11_from_xorg))
return &c->x11_from_xorg;
}
X11Context *context_get_x11_context_safe(Context *c) {
- return &ASSERT_PTR(c)->x11_from_xorg;
+ assert(c);
+ return context_get_x11_context(c) ?: &c->x11_from_vc;
}
int locale_read_data(Context *c, sd_bus_message *m) {
c->vc_stat = st;
context_clear_vconsole(c);
+ x11_context_clear(&c->x11_from_vc);
return parse_env_file_fd(fd, "/etc/vconsole.conf",
"KEYMAP", &c->vc_keymap,
- "KEYMAP_TOGGLE", &c->vc_keymap_toggle);
+ "KEYMAP_TOGGLE", &c->vc_keymap_toggle,
+ "XKB_LAYOUT", &c->x11_from_vc.layout,
+ "XKB_MODEL", &c->x11_from_vc.model,
+ "XKB_VARIANT", &c->x11_from_vc.variant,
+ "XKB_OPTIONS", &c->x11_from_vc.options);
}
int x11_read_data(Context *c, sd_bus_message *m) {
assert(c);
+ r = vconsole_read_data(c, m);
+ if (r < 0)
+ return r;
+
+ if (!x11_context_isempty(&c->x11_from_vc)) {
+ log_debug("XKB settings loaded from vconsole.conf, not reading xorg.conf.d/00-keyboard.conf.");
+ return 0;
+ }
+
/* Do not try to re-read the file within single bus operation. */
if (m) {
if (m == c->x11_cache)
int vconsole_write_data(Context *c) {
_cleanup_strv_free_ char **l = NULL;
+ const X11Context *xc;
int r;
assert(c);
+ xc = context_get_x11_context(c);
+
+ /* If the X11 context is from xorg.conf, then sync one from vconsole.conf with it. */
+ r = x11_context_copy(&c->x11_from_vc, xc);
+ if (r < 0)
+ return r;
+
r = load_env_file(NULL, "/etc/vconsole.conf", &l);
if (r < 0 && r != -ENOENT)
return r;
if (r < 0)
return r;
+ r = strv_env_assign(&l, "XKB_LAYOUT", xc ? empty_to_null(xc->layout) : NULL);
+ if (r < 0)
+ return r;
+
+ r = strv_env_assign(&l, "XKB_MODEL", xc ? empty_to_null(xc->model) : NULL);
+ if (r < 0)
+ return r;
+
+ r = strv_env_assign(&l, "XKB_VARIANT", xc ? empty_to_null(xc->variant) : NULL);
+ if (r < 0)
+ return r;
+
+ r = strv_env_assign(&l, "XKB_OPTIONS", xc ? empty_to_null(xc->options) : NULL);
+ if (r < 0)
+ return r;
+
if (strv_isempty(l)) {
if (unlink("/etc/vconsole.conf") < 0)
return errno == ENOENT ? 0 : -errno;
assert(c);
+ /* If Context.x11_from_vc is empty, then here we update Context.x11_from_xorg, as the caller may
+ * already have been called context_get_x11_context() or _safe(), and otherwise the caller's
+ * X11Context may be outdated. The updated context will be copied to Context.x11_from_vc in
+ * vconsole_write_data() if necessary. */
xc = context_get_x11_context_safe(c);
if (isempty(c->vc_keymap)) {
sd_bus_message *x11_cache;
struct stat x11_stat;
X11Context x11_from_xorg;
+ X11Context x11_from_vc;
sd_bus_message *vc_cache;
struct stat vc_stat;
return log_oom();
if (convert) {
- r = vconsole_read_data(c, m);
- if (r < 0) {
- log_error_errno(r, "Failed to read virtual console keymap data: %m");
- return sd_bus_error_set_errnof(error, r, "Failed to read virtual console keymap data: %m");
- }
-
r = x11_convert_to_vconsole(c);
if (r < 0) {
log_error_errno(r, "Failed to convert keymap data: %m");
convert = r > 0;
}
- if (convert) {
- r = vconsole_write_data(c);
- if (r < 0)
- log_warning_errno(r, "Failed to update vconsole.conf, ignoring: %m");
- }
+ r = vconsole_write_data(c);
+ if (r < 0)
+ log_warning_errno(r, "Failed to update vconsole.conf, ignoring: %m");
r = x11_write_data(c);
if (r < 0)
TEST(vconsole_convert_to_x11) {
_cleanup_(context_clear) Context c = {};
- X11Context *xc = &c.x11_from_xorg;
+ X11Context *xc = &c.x11_from_vc;
log_info("/* test emptying first (:) */");
assert_se(free_and_strdup(&xc->layout, "foo") >= 0);
}
test_vc_keymap() {
- local i output
+ local i output vc
if [[ -z "$(localectl list-keymaps)" ]]; then
echo "No vconsole keymap installed, skipping test."
# clear previous conversion from VC -> X11 keymap
systemctl stop systemd-localed.service
wait_vconsole_setup
- rm -f /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
+ rm -f /etc/vconsole.conf /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
# set VC keymap
assert_rc 0 localectl set-keymap "$i"
output=$(localectl)
# check VC keymap
- assert_in "KEYMAP=$i" "$(cat /etc/vconsole.conf)"
+ vc=$(cat /etc/vconsole.conf)
+ assert_in "KEYMAP=$i" "$vc"
assert_in "VC Keymap: $i" "$output"
# check VC -> X11 keymap conversion
assert_in "X11 Model: pc105\+inet" "$output"
assert_not_in "X11 Variant:" "$output"
assert_in "X11 Options: terminate:ctrl_alt_bksp" "$output"
+
+ assert_in "XKB_LAYOUT=us" "$vc"
+ assert_in "XKB_MODEL=pc105\+inet" "$vc"
+ assert_not_in "XKB_VARIANT" "$vc"
+ assert_in "XKB_OPTIONS=terminate:ctrl_alt_bksp" "$vc"
elif [[ "$i" == "us-acentos" ]]; then
assert_in "X11 Layout: us" "$output"
assert_in 'X11 Model: pc105$' "$output"
assert_in "X11 Variant: intl" "$output"
assert_in "X11 Options: terminate:ctrl_alt_bksp" "$output"
+
+ assert_in "XKB_LAYOUT=us" "$vc"
+ assert_in "XKB_MODEL=pc105$" "$vc"
+ assert_in "XKB_VARIANT=intl" "$vc"
+ assert_in "XKB_OPTIONS=terminate:ctrl_alt_bksp" "$vc"
elif [[ "$i" =~ ^us-.* ]]; then
assert_in "X11 Layout: .unset." "$output"
assert_not_in "X11 Model:" "$output"
assert_not_in "X11 Variant:" "$output"
assert_not_in "X11 Options:" "$output"
+
+ assert_not_in "XKB_LAYOUT" "$vc"
+ assert_not_in "XKB_MODEL" "$vc"
+ assert_not_in "XKB_VARIANT" "$vc"
+ assert_not_in "XKB_OPTIONS" "$vc"
fi
done
assert_in 'Option "XkbModel" "pc105\+inet"' "$output"
assert_in 'Option "XkbVariant" "intl"' "$output"
assert_in 'Option "XkbOptions" "terminate:ctrl_alt_bksp"' "$output"
+
+ output=$(cat /etc/vconsole.conf)
+ assert_in 'XKB_LAYOUT=us' "$output"
+ assert_in 'XKB_MODEL=pc105\+inet' "$output"
+ assert_in 'XKB_VARIANT=intl' "$output"
+ assert_in 'XKB_OPTIONS=terminate:ctrl_alt_bksp' "$output"
fi
output=$(localectl)
assert_in 'Option "XkbModel" "pc105\+inet"' "$output"
assert_in 'Option "XkbVariant" "intl"' "$output"
assert_not_in 'Option "XkbOptions"' "$output"
+
+ output=$(cat /etc/vconsole.conf)
+ assert_in 'XKB_LAYOUT=us' "$output"
+ assert_in 'XKB_MODEL=pc105\+inet' "$output"
+ assert_in 'XKB_VARIANT=intl' "$output"
+ assert_not_in 'XKB_OPTIONS' "$output"
fi
output=$(localectl)
assert_in 'Option "XkbModel" "pc105\+inet"' "$output"
assert_not_in 'Option "XkbVariant"' "$output"
assert_not_in 'Option "XkbOptions"' "$output"
+
+ output=$(cat /etc/vconsole.conf)
+ assert_in 'XKB_LAYOUT=us' "$output"
+ assert_in 'XKB_MODEL=pc105\+inet' "$output"
+ assert_not_in 'XKB_VARIANT' "$output"
+ assert_not_in 'XKB_OPTIONS' "$output"
fi
output=$(localectl)
assert_not_in 'Option "XkbModel"' "$output"
assert_not_in 'Option "XkbVariant"' "$output"
assert_not_in 'Option "XkbOptions"' "$output"
+
+ output=$(cat /etc/vconsole.conf)
+ assert_in 'XKB_LAYOUT=us' "$output"
+ assert_not_in 'XKB_MODEL' "$output"
+ assert_not_in 'XKB_VARIANT' "$output"
+ assert_not_in 'XKB_OPTIONS' "$output"
fi
output=$(localectl)
# gets along without config file
systemctl stop systemd-localed.service
- rm -f /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
+ rm -f /etc/vconsole.conf /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
output=$(localectl)
assert_in "X11 Layout: .unset." "$output"
assert_not_in "X11 Model:" "$output"