X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-session.c;h=65bbb77750b27ffdb1d575b02d3ce3c78c6c7ff8;hb=492d7a3038b154e1813a1ece913a5a27148fec19;hp=eeb58c9031b71d1bce41805cb778e6d4c7890d30;hpb=d5099efc47d4e6ac60816b5381a5f607ab03f06e;p=elogind.git diff --git a/src/login/logind-session.c b/src/login/logind-session.c index eeb58c903..65bbb7775 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -1053,6 +1053,31 @@ void session_restore_vt(Session *s) { s->vtfd = safe_close(s->vtfd); } +void session_leave_vt(Session *s) { + int r; + + assert(s); + + /* This is called whenever we get a VT-switch signal from the kernel. + * We acknowledge all of them unconditionally. Note that session are + * free to overwrite those handlers and we only register them for + * sessions with controllers. Legacy sessions are not affected. + * However, if we switch from a non-legacy to a legacy session, we must + * make sure to pause all device before acknowledging the switch. We + * process the real switch only after we are notified via sysfs, so the + * legacy session might have already started using the devices. If we + * don't pause the devices before the switch, we might confuse the + * session we switch to. */ + + if (s->vtfd < 0) + return; + + session_device_pause_all(s); + r = ioctl(s->vtfd, VT_RELDISP, 1); + if (r < 0) + log_debug("Cannot release VT of session %s: %m", s->id); +} + bool session_is_controller(Session *s, const char *sender) { assert(s);