From 27dafac92b660eb7c2268b824b0b3df95e62869e Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Mon, 27 Aug 2018 22:42:00 +0200 Subject: [PATCH] terminal-util: introduce vt_release() helper --- src/basic/terminal-util.c | 16 ++++++++++++++++ src/basic/terminal-util.h | 1 + src/login/logind-session.c | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index aefa7cd4ef9..7fce84bf821 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -1305,3 +1305,19 @@ int vt_restore(int fd) { return q; } + +int vt_release(int fd, bool restore) { + assert(fd >= 0); + + /* This function releases the VT by acknowledging the VT-switch signal + * sent by the kernel and optionally reset the VT in text and auto + * VT-switching modes. */ + + if (ioctl(fd, VT_RELDISP, 1) < 0) + return -errno; + + if (restore) + return vt_restore(fd); + + return 0; +} diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index 2d931114e49..86e730028e4 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -155,3 +155,4 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode); int vt_default_utf8(void); int vt_reset_keyboard(int fd); int vt_restore(int fd); +int vt_release(int fd, bool restore_vt); diff --git a/src/login/logind-session.c b/src/login/logind-session.c index f35d7808c05..e8be1ffbedb 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -1296,9 +1296,9 @@ void session_leave_vt(Session *s) { return; session_device_pause_all(s); - r = ioctl(s->vtfd, VT_RELDISP, 1); + r = vt_release(s->vtfd, false); if (r < 0) - log_debug_errno(errno, "Cannot release VT of session %s: %m", s->id); + log_debug_errno(r, "Cannot release VT of session %s: %m", s->id); } bool session_is_controller(Session *s, const char *sender) {