From 192a11a476da66524b4b98a6a345df701c9e8ff3 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 26 Jan 2023 18:04:12 +0100 Subject: [PATCH] Allow recovering from tty switching failures If we fail to switch tty when showing the greeter, exit saying so then switch back to tty 1 and try launching the Display again. Fixes #1636 --- src/auth/Auth.h | 1 + src/daemon/Display.cpp | 17 +++++++++++++---- src/daemon/Greeter.cpp | 7 ++++--- src/daemon/Greeter.h | 1 + src/helper/UserSession.cpp | 2 +- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/auth/Auth.h b/src/auth/Auth.h index 0e39f690..66a9ec97 100644 --- a/src/auth/Auth.h +++ b/src/auth/Auth.h @@ -86,6 +86,7 @@ namespace SDDM { HELPER_SESSION_ERROR, HELPER_OTHER_ERROR, HELPER_DISPLAYSERVER_ERROR, + HELPER_TTY_ERROR, }; Q_ENUM(HelperExitStatus) diff --git a/src/daemon/Display.cpp b/src/daemon/Display.cpp index c2437c70..ea0c7060 100644 --- a/src/daemon/Display.cpp +++ b/src/daemon/Display.cpp @@ -52,6 +52,8 @@ #include "VirtualTerminal.h" #include "WaylandDisplayServer.h" +static int s_ttyFailures = 0; + namespace SDDM { bool isTtyInUse(const QString &desiredTty) { @@ -149,10 +151,17 @@ namespace SDDM { connect(this, &Display::loginFailed, m_socketServer, &SocketServer::loginFailed); connect(this, &Display::loginSucceeded, m_socketServer, &SocketServer::loginSucceeded); - connect(m_greeter, &Greeter::failed, - QCoreApplication::instance(), [] { - QCoreApplication::instance()->exit(23); - }); + connect(m_greeter, &Greeter::failed, this, &Display::stop); + connect(m_greeter, &Greeter::ttyFailed, this, [this] { + ++s_ttyFailures; + if (s_ttyFailures > 5) { + QCoreApplication::exit(23); + } + // It might be the case that we are trying a tty that has been taken over by a + // different process. In such a case, switch back to the initial one and try again. + VirtualTerminal::jumpToVt(1, true); + stop(); + }); connect(m_greeter, &Greeter::displayServerFailed, this, &Display::displayServerFailed); } diff --git a/src/daemon/Greeter.cpp b/src/daemon/Greeter.cpp index eadae5ae..ea9ad814 100644 --- a/src/daemon/Greeter.cpp +++ b/src/daemon/Greeter.cpp @@ -32,6 +32,7 @@ #include #include +#include namespace SDDM { Greeter::Greeter(Display *parent) @@ -312,9 +313,9 @@ namespace SDDM { if (status == Auth::HELPER_DISPLAYSERVER_ERROR) { Q_EMIT displayServerFailed(); - } - - if (status == Auth::HELPER_SESSION_ERROR) { + } else if (status == Auth::HELPER_TTY_ERROR) { + Q_EMIT ttyFailed(); + } else if (status == Auth::HELPER_SESSION_ERROR) { Q_EMIT failed(); } } diff --git a/src/daemon/Greeter.h b/src/daemon/Greeter.h index 5a69ccd9..3a6295ca 100644 --- a/src/daemon/Greeter.h +++ b/src/daemon/Greeter.h @@ -62,6 +62,7 @@ namespace SDDM { void authError(const QString &message, Auth::Error error); signals: + void ttyFailed(); void failed(); void displayServerFailed(); diff --git a/src/helper/UserSession.cpp b/src/helper/UserSession.cpp index c8cb657c..090de5ff 100644 --- a/src/helper/UserSession.cpp +++ b/src/helper/UserSession.cpp @@ -180,7 +180,7 @@ namespace SDDM { if (ioctl(STDIN_FILENO, TIOCSCTTY) < 0) { const auto error = strerror(errno); qCritical().nospace() << "Failed to take control of " << ttyString << " (" << QFileInfo(ttyString).owner() << "): " << error; - exit(Auth::HELPER_OTHER_ERROR); + exit(Auth::HELPER_TTY_ERROR); } }