tty: Put console in K_OFF mode
This disables all kernel key bindings (VT switch keybindings, caps lock etc) and disables delivery of console input.
This commit is contained in:
@@ -39,10 +39,10 @@ struct tty {
|
|||||||
int fd;
|
int fd;
|
||||||
struct termios terminal_attributes;
|
struct termios terminal_attributes;
|
||||||
|
|
||||||
struct wl_event_source *input_source;
|
|
||||||
struct wl_event_source *vt_source;
|
struct wl_event_source *vt_source;
|
||||||
tty_vt_func_t vt_func;
|
tty_vt_func_t vt_func;
|
||||||
int vt, starting_vt, has_vt;
|
int vt, starting_vt, has_vt;
|
||||||
|
int kb_mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int vt_handler(int signal_number, void *data)
|
static int vt_handler(int signal_number, void *data)
|
||||||
@@ -64,18 +64,6 @@ static int vt_handler(int signal_number, void *data)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
on_tty_input(int fd, uint32_t mask, void *data)
|
|
||||||
{
|
|
||||||
struct tty *tty = data;
|
|
||||||
|
|
||||||
/* Ignore input to tty. We get keyboard events from evdev
|
|
||||||
*/
|
|
||||||
tcflush(tty->fd, TCIFLUSH);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
try_open_vt(struct tty *tty)
|
try_open_vt(struct tty *tty)
|
||||||
{
|
{
|
||||||
@@ -186,17 +174,17 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
|
|||||||
if (tcsetattr(tty->fd, TCSANOW, &raw_attributes) < 0)
|
if (tcsetattr(tty->fd, TCSANOW, &raw_attributes) < 0)
|
||||||
fprintf(stderr, "could not put terminal into raw mode: %m\n");
|
fprintf(stderr, "could not put terminal into raw mode: %m\n");
|
||||||
|
|
||||||
loop = wl_display_get_event_loop(compositor->wl_display);
|
ioctl(tty->fd, KDGKBMODE, &tty->kb_mode);
|
||||||
tty->input_source =
|
ret = ioctl(tty->fd, KDSKBMODE, K_OFF);
|
||||||
wl_event_loop_add_fd(loop, tty->fd,
|
if (ret) {
|
||||||
WL_EVENT_READABLE, on_tty_input, tty);
|
fprintf(stderr, "failed to set K_OFF keyboard mode on tty: %m\n");
|
||||||
if (!tty->input_source)
|
|
||||||
goto err_attr;
|
goto err_attr;
|
||||||
|
}
|
||||||
|
|
||||||
ret = ioctl(tty->fd, KDSETMODE, KD_GRAPHICS);
|
ret = ioctl(tty->fd, KDSETMODE, KD_GRAPHICS);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "failed to set KD_GRAPHICS mode on tty: %m\n");
|
fprintf(stderr, "failed to set KD_GRAPHICS mode on tty: %m\n");
|
||||||
goto err_input_source;
|
goto err_kdkbmode;
|
||||||
}
|
}
|
||||||
|
|
||||||
tty->has_vt = 1;
|
tty->has_vt = 1;
|
||||||
@@ -208,6 +196,7 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
|
|||||||
goto err_kdmode;
|
goto err_kdmode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loop = wl_display_get_event_loop(compositor->wl_display);
|
||||||
tty->vt_source =
|
tty->vt_source =
|
||||||
wl_event_loop_add_signal(loop, SIGUSR1, vt_handler, tty);
|
wl_event_loop_add_signal(loop, SIGUSR1, vt_handler, tty);
|
||||||
if (!tty->vt_source)
|
if (!tty->vt_source)
|
||||||
@@ -221,8 +210,8 @@ err_vtmode:
|
|||||||
err_kdmode:
|
err_kdmode:
|
||||||
ioctl(tty->fd, KDSETMODE, KD_TEXT);
|
ioctl(tty->fd, KDSETMODE, KD_TEXT);
|
||||||
|
|
||||||
err_input_source:
|
err_kdkbmode:
|
||||||
wl_event_source_remove(tty->input_source);
|
ioctl(tty->fd, KDSKBMODE, tty->kb_mode);
|
||||||
|
|
||||||
err_attr:
|
err_attr:
|
||||||
tcsetattr(tty->fd, TCSANOW, &tty->terminal_attributes);
|
tcsetattr(tty->fd, TCSANOW, &tty->terminal_attributes);
|
||||||
@@ -241,6 +230,9 @@ tty_destroy(struct tty *tty)
|
|||||||
if(!tty)
|
if(!tty)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (ioctl(tty->fd, KDSKBMODE, tty->kb_mode))
|
||||||
|
fprintf(stderr, "failed to restore keyboard mode: %m\n");
|
||||||
|
|
||||||
if (ioctl(tty->fd, KDSETMODE, KD_TEXT))
|
if (ioctl(tty->fd, KDSETMODE, KD_TEXT))
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"failed to set KD_TEXT mode on tty: %m\n");
|
"failed to set KD_TEXT mode on tty: %m\n");
|
||||||
@@ -258,7 +250,6 @@ tty_destroy(struct tty *tty)
|
|||||||
ioctl(tty->fd, VT_WAITACTIVE, tty->starting_vt);
|
ioctl(tty->fd, VT_WAITACTIVE, tty->starting_vt);
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_event_source_remove(tty->input_source);
|
|
||||||
wl_event_source_remove(tty->vt_source);
|
wl_event_source_remove(tty->vt_source);
|
||||||
|
|
||||||
close(tty->fd);
|
close(tty->fd);
|
||||||
|
|||||||
Reference in New Issue
Block a user