From adb8688b3ff445d9c48ed0d72208c7844c2acc01 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Mon, 27 Aug 2018 23:16:10 +0200 Subject: [PATCH] logind: stop managing VT switches if no sessions are registered on that VT When no sessions are registered on a given VT (anymore), we should always let the kernel processes VT switching (instead of simply emitting a warning) otherwise the requests sent by the kernel are simply ignored making the VT switch requested by users simply impossible. Even if it shouldn't happen, this case was encountered in issue #9754, so better to be safe than sorry. --- src/login/logind.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/login/logind.c b/src/login/logind.c index f419186506f..b8530520efe 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -25,6 +25,7 @@ #include "selinux-util.h" #include "signal-util.h" #include "strv.h" +#include "terminal-util.h" static Manager* manager_unref(Manager *m); DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_unref); @@ -747,7 +748,29 @@ static int manager_vt_switch(sd_event_source *src, const struct signalfd_siginfo active = m->seat0->active; if (!active || active->vtnr < 1) { - log_warning("Received VT_PROCESS signal without a registered session on that VT."); + _cleanup_close_ int fd = -1; + int r; + + /* We are requested to acknowledge the VT-switch signal by the kernel but + * there's no registered sessions for the current VT. Normally this + * shouldn't happen but something wrong might have happened when we tried + * to release the VT. Better be safe than sorry, and try to release the VT + * one more time otherwise the user will be locked with the current VT. */ + + log_warning("Received VT_PROCESS signal without a registered session, restoring VT."); + + /* At this point we only have the kernel mapping for referring to the + * current VT. */ + fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK); + if (fd < 0) { + log_warning_errno(fd, "Failed to open, ignoring: %m"); + return 0; + } + + r = vt_release(fd, true); + if (r < 0) + log_warning_errno(r, "Failed to release VT, ignoring: %m"); + return 0; } -- 2.47.3