diff options
-rw-r--r-- | src/basic/terminal-util.c | 26 | ||||
-rw-r--r-- | src/basic/terminal-util.h | 1 | ||||
-rw-r--r-- | src/vconsole/vconsole-setup.c | 30 |
3 files changed, 36 insertions, 21 deletions
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index cd878551f4..71238ac9c4 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -1249,12 +1249,36 @@ int vt_default_utf8(void) { return parse_boolean(b); } +int vt_verify_kbmode(int fd) { + int curr_mode; + + /* + * Make sure we only adjust consoles in K_XLATE or K_UNICODE mode. + * Otherwise we would (likely) interfere with X11's processing of the + * key events. + * + * http://lists.freedesktop.org/archives/systemd-devel/2013-February/008573.html + */ + + if (ioctl(fd, KDGKBMODE, &curr_mode) < 0) + return -errno; + + return IN_SET(curr_mode, K_XLATE, K_UNICODE) ? 0 : -EBUSY; +} + int vt_reset_keyboard(int fd) { - int kb; + int kb, r; /* If we can't read the default, then default to unicode. It's 2017 after all. */ kb = vt_default_utf8() != 0 ? K_UNICODE : K_XLATE; + r = vt_verify_kbmode(fd); + if (r == -EBUSY) { + log_debug_errno(r, "Keyboard is not in XLATE or UNICODE mode, not resetting: %m"); + return 0; + } else if (r < 0) + return r; + if (ioctl(fd, KDSKBMODE, kb) < 0) return -errno; diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index f3e785e7ba..2a1851c0f1 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -156,6 +156,7 @@ int openpt_in_namespace(pid_t pid, int flags); int open_terminal_in_namespace(pid_t pid, const char *name, int mode); int vt_default_utf8(void); +int vt_verify_kbmode(int fd); int vt_reset_keyboard(int fd); int vt_restore(int fd); int vt_release(int fd, bool restore_vt); diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index 976dd825bc..d2bc3921d2 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -70,29 +70,19 @@ static int verify_vc_allocation_byfd(int fd) { return verify_vc_allocation(vcs.v_active); } -static int verify_vc_kbmode(int fd) { - int curr_mode; - - /* - * Make sure we only adjust consoles in K_XLATE or K_UNICODE mode. - * Otherwise we would (likely) interfere with X11's processing of the - * key events. - * - * http://lists.freedesktop.org/archives/systemd-devel/2013-February/008573.html - */ - - if (ioctl(fd, KDGKBMODE, &curr_mode) < 0) - return -errno; - - return IN_SET(curr_mode, K_XLATE, K_UNICODE) ? 0 : -EBUSY; -} - static int toggle_utf8(const char *name, int fd, bool utf8) { int r; struct termios tc = {}; assert(name); + r = vt_verify_kbmode(fd); + if (r == -EBUSY) { + log_warning_errno(r, "Virtual console %s is not in K_XLATE or K_UNICODE: %m", name); + return 0; + } else if (r < 0) + return log_warning_errno(r, "Failed to verify kbdmode on %s: %m", name); + r = ioctl(fd, KDSKBMODE, utf8 ? K_UNICODE : K_XLATE); if (r < 0) return log_warning_errno(errno, "Failed to %s UTF-8 kbdmode on %s: %m", enable_disable(utf8), name); @@ -290,7 +280,7 @@ static void setup_remaining_vcs(int src_fd, unsigned src_idx, bool utf8) { continue; } - if (verify_vc_kbmode(fd_d) < 0) + if (vt_verify_kbmode(fd_d) < 0) continue; toggle_utf8(ttyname, fd_d, utf8); @@ -365,7 +355,7 @@ static int find_source_vc(char **ret_path, unsigned *ret_idx) { err = -fd; continue; } - r = verify_vc_kbmode(fd); + r = vt_verify_kbmode(fd); if (r < 0) { if (!err) err = -r; @@ -398,7 +388,7 @@ static int verify_source_vc(char **ret_path, const char *src_vc) { if (r < 0) return log_error_errno(r, "Virtual console %s is not allocated: %m", src_vc); - r = verify_vc_kbmode(fd); + r = vt_verify_kbmode(fd); if (r < 0) return log_error_errno(r, "Virtual console %s is not in K_XLATE or K_UNICODE: %m", src_vc); |