terminal-util: introduce vt_restore() helper
This commit is contained in:
parent
0212126c45
commit
6179ede1c5
|
@ -1271,3 +1271,37 @@ int vt_reset_keyboard(int fd) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vt_restore(int fd) {
|
||||||
|
static const struct vt_mode mode = {
|
||||||
|
.mode = VT_AUTO,
|
||||||
|
};
|
||||||
|
int r, q = 0;
|
||||||
|
|
||||||
|
r = ioctl(fd, KDSETMODE, KD_TEXT);
|
||||||
|
if (r < 0)
|
||||||
|
q = log_debug_errno(errno, "Failed to set VT in text mode, ignoring: %m");
|
||||||
|
|
||||||
|
r = vt_reset_keyboard(fd);
|
||||||
|
if (r < 0) {
|
||||||
|
log_debug_errno(r, "Failed to reset keyboard mode, ignoring: %m");
|
||||||
|
if (q >= 0)
|
||||||
|
q = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = ioctl(fd, VT_SETMODE, &mode);
|
||||||
|
if (r < 0) {
|
||||||
|
log_debug_errno(errno, "Failed to set VT_AUTO mode, ignoring: %m");
|
||||||
|
if (q >= 0)
|
||||||
|
q = -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = fchown(fd, 0, (gid_t) -1);
|
||||||
|
if (r < 0) {
|
||||||
|
log_debug_errno(errno, "Failed to chown VT, ignoring: %m");
|
||||||
|
if (q >= 0)
|
||||||
|
q = -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
return q;
|
||||||
|
}
|
||||||
|
|
|
@ -154,3 +154,4 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode);
|
||||||
|
|
||||||
int vt_default_utf8(void);
|
int vt_default_utf8(void);
|
||||||
int vt_reset_keyboard(int fd);
|
int vt_reset_keyboard(int fd);
|
||||||
|
int vt_restore(int fd);
|
||||||
|
|
|
@ -1225,12 +1225,7 @@ error:
|
||||||
}
|
}
|
||||||
|
|
||||||
static void session_restore_vt(Session *s) {
|
static void session_restore_vt(Session *s) {
|
||||||
|
int r, vt, old_fd;
|
||||||
static const struct vt_mode mode = {
|
|
||||||
.mode = VT_AUTO,
|
|
||||||
};
|
|
||||||
|
|
||||||
int vt, old_fd;
|
|
||||||
|
|
||||||
/* We need to get a fresh handle to the virtual terminal,
|
/* We need to get a fresh handle to the virtual terminal,
|
||||||
* since the old file-descriptor is potentially in a hung-up
|
* since the old file-descriptor is potentially in a hung-up
|
||||||
|
@ -1246,12 +1241,9 @@ static void session_restore_vt(Session *s) {
|
||||||
if (vt < 0)
|
if (vt < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
(void) ioctl(vt, KDSETMODE, KD_TEXT);
|
r = vt_restore(vt);
|
||||||
|
if (r < 0)
|
||||||
(void) vt_reset_keyboard(vt);
|
log_warning_errno(r, "Failed to restore VT, ignoring: %m");
|
||||||
|
|
||||||
(void) ioctl(vt, VT_SETMODE, &mode);
|
|
||||||
(void) fchown(vt, 0, (gid_t) -1);
|
|
||||||
|
|
||||||
s->vtfd = safe_close(s->vtfd);
|
s->vtfd = safe_close(s->vtfd);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue