feat(session): verify switches and recover when the greeter stays away
logind accepts loginctl activate and SwitchToGreeter before the graphics stack moves the seat, and SDDM 0.21 answers SwitchToGreeter with a greeter whose logins never start a session. Each request is now confirmed within a timeout and the previous session is reactivated on failure, so no path can leave a blank VT. When nothing answers, both front-ends offer to restart display-manager.service through polkit, and only after that is the session terminated.
This commit is contained in:
5 files changed
+521
-54
No files matched your search
+156
-16
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "desktop-catalog.h"
|
||||
#include "session-catalog.h"
|
||||
#include "session-switcher.h"
|
||||
|
||||
namespace {
|
||||
@@ -69,7 +70,7 @@ private:
|
||||
self->switchTo(*row.profile);
|
||||
break;
|
||||
case RowMode::Greeter:
|
||||
self->askGreeter();
|
||||
self->askGreeter(*row.profile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -92,18 +93,36 @@ private:
|
||||
g_clear_object(&self->pending_);
|
||||
}
|
||||
|
||||
static void onGreeterResponse(GtkAlertDialog*, int response, gpointer data) {
|
||||
// GtkAlertDialog exposes no "response" signal: the chosen button index is
|
||||
// only available from gtk_alert_dialog_choose_finish().
|
||||
static void onGreeterChosen(GObject* source, GAsyncResult* result, gpointer data) {
|
||||
auto* self = static_cast<ManagerWindow*>(data);
|
||||
GError* error = nullptr;
|
||||
const int response =
|
||||
gtk_alert_dialog_choose_finish(GTK_ALERT_DIALOG(source), result, &error);
|
||||
if (error != nullptr) {
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
if (response != 1) {
|
||||
return;
|
||||
}
|
||||
self->goToGreeter(false);
|
||||
}
|
||||
|
||||
static void onForceChosen(GObject* source, GAsyncResult* result, gpointer data) {
|
||||
auto* self = static_cast<ManagerWindow*>(data);
|
||||
std::string error;
|
||||
if (!fws::switchToGreeter(error)) {
|
||||
self->showError("Impossible de revenir au greeter : " + error);
|
||||
} else {
|
||||
self->setStatus("Retour à l'écran de connexion…");
|
||||
GError* error = nullptr;
|
||||
const int response =
|
||||
gtk_alert_dialog_choose_finish(GTK_ALERT_DIALOG(source), result, &error);
|
||||
if (error != nullptr) {
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
if (response != 1) {
|
||||
return;
|
||||
}
|
||||
self->goToGreeter(true);
|
||||
}
|
||||
|
||||
void buildWindow(GtkApplication* application) {
|
||||
@@ -223,11 +242,30 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// The session this window runs in: XDG_SESSION_ID, or the seat's active one
|
||||
// when the variable is missing (pkexec, systemd-run...).
|
||||
fws::SessionInfo currentSession() const {
|
||||
fws::SessionInfo session;
|
||||
if (fws::findGraphicalSession(fws::currentSessionId(), session)) {
|
||||
return session;
|
||||
}
|
||||
fws::findGraphicalSession(fws::activeGraphicalSessionId(), session);
|
||||
return session;
|
||||
}
|
||||
|
||||
// Lets the status text paint before the blocking logind calls run.
|
||||
static void flushPendingEvents() {
|
||||
while (g_main_context_iteration(nullptr, FALSE) != FALSE) {
|
||||
}
|
||||
}
|
||||
|
||||
void refreshRows() {
|
||||
const std::string current = currentSession().id;
|
||||
for (RowWidgets& row : rows_) {
|
||||
std::string sessionId;
|
||||
const bool installed = fws::isDesktopInstalled(*row.profile);
|
||||
const bool active = installed && fws::findActiveSession(*row.profile, sessionId);
|
||||
const bool isCurrent = active && !current.empty() && sessionId == current;
|
||||
|
||||
gtk_widget_remove_css_class(row.action, "suggested-action");
|
||||
gtk_widget_remove_css_class(row.action, "destructive-action");
|
||||
@@ -238,6 +276,14 @@ private:
|
||||
gtk_button_set_label(GTK_BUTTON(row.action), "Installer");
|
||||
gtk_widget_add_css_class(row.action, "suggested-action");
|
||||
row.mode = RowMode::Install;
|
||||
} else if (isCurrent) {
|
||||
gtk_label_set_markup(GTK_LABEL(row.status),
|
||||
"<span foreground='#26a269'>Installé</span> · session actuelle");
|
||||
// Activating the session already on screen would do nothing, so
|
||||
// the useful action from here is leaving for the greeter.
|
||||
gtk_button_set_label(GTK_BUTTON(row.action), "Écran de connexion");
|
||||
gtk_widget_add_css_class(row.action, "suggested-action");
|
||||
row.mode = RowMode::Greeter;
|
||||
} else if (active) {
|
||||
gtk_label_set_markup(GTK_LABEL(row.status),
|
||||
"<span foreground='#26a269'>Installé</span> · session active");
|
||||
@@ -245,8 +291,20 @@ private:
|
||||
gtk_widget_add_css_class(row.action, "suggested-action");
|
||||
row.mode = RowMode::SwitchTo;
|
||||
} else {
|
||||
gtk_label_set_markup(GTK_LABEL(row.status),
|
||||
"<span foreground='#26a269'>Installé</span> · aucune session");
|
||||
// The greeter opens on the session it remembered, not on the one
|
||||
// this row points at, so the entry to pick is named right here.
|
||||
const std::string entry = fws::greeterSessionName(row.profile->sessionNames);
|
||||
if (entry.empty()) {
|
||||
gtk_label_set_markup(GTK_LABEL(row.status),
|
||||
"<span foreground='#26a269'>Installé</span> · aucune session");
|
||||
} else {
|
||||
gchar* markup = g_markup_printf_escaped(
|
||||
"<span foreground='#26a269'>Installé</span> · aucune session · choisir "
|
||||
"« %s » au greeter",
|
||||
entry.c_str());
|
||||
gtk_label_set_markup(GTK_LABEL(row.status), markup);
|
||||
g_free(markup);
|
||||
}
|
||||
gtk_button_set_label(GTK_BUTTON(row.action), "Écran de connexion");
|
||||
gtk_widget_add_css_class(row.action, "destructive-action");
|
||||
row.mode = RowMode::Greeter;
|
||||
@@ -312,28 +370,107 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
if (sessionId == currentSession().id) {
|
||||
setStatus("Vous êtes déjà sur " + profile.name + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
// activateSession waits for the seat to move and rolls back, so the
|
||||
// window blocks for a few seconds instead of leaving a black VT behind.
|
||||
setStatus("Bascule vers " + profile.name + "…");
|
||||
flushPendingEvents();
|
||||
|
||||
std::string error;
|
||||
if (!fws::activateSession(sessionId, error)) {
|
||||
showError("Échec de la bascule : " + error);
|
||||
setStatus("La session précédente a été conservée.");
|
||||
return;
|
||||
}
|
||||
setStatus("Bascule vers " + profile.name + "…");
|
||||
}
|
||||
|
||||
void askGreeter() {
|
||||
GtkAlertDialog* dialog = gtk_alert_dialog_new(
|
||||
"%s",
|
||||
"La session graphique courante sera fermée. Les applications non enregistrées "
|
||||
"seront perdues. Continuer ?");
|
||||
// The greeter starts whichever session its own selector is set on, and no
|
||||
// bus API lets us choose it: the dialog names the entry to pick before the
|
||||
// user is sent to another VT, where this window is no longer visible.
|
||||
void askGreeter(const fws::DesktopProfile& profile) {
|
||||
std::string sessionId;
|
||||
const bool running = fws::findActiveSession(profile, sessionId);
|
||||
greeterIsCurrent_ = running && sessionId == currentSession().id;
|
||||
greeterEntry_ = fws::greeterSessionName(profile.sessionNames);
|
||||
|
||||
std::string message;
|
||||
if (greeterIsCurrent_) {
|
||||
message = profile.name +
|
||||
" tourne deja dans votre session. Sur l'ecran de connexion, ouvrez le "
|
||||
"selecteur de session et choisissez un autre environnement : relancer "
|
||||
"le meme environnement ne demarre pas une seconde session. Rien n'est "
|
||||
"ferme ici.";
|
||||
} else if (!greeterEntry_.empty()) {
|
||||
message = "L'ecran de connexion va s'afficher. Choisissez « " + greeterEntry_ +
|
||||
" » dans le selecteur de session, puis connectez-vous : c'est ce choix "
|
||||
"qui decide de l'environnement demarre.";
|
||||
} else {
|
||||
message = "L'ecran de connexion va s'afficher. Choisissez " + profile.name +
|
||||
" dans le selecteur de session, puis connectez-vous.";
|
||||
}
|
||||
|
||||
GtkAlertDialog* dialog = gtk_alert_dialog_new("%s", message.c_str());
|
||||
const char* buttons[] = {"Annuler", "Continuer", nullptr};
|
||||
gtk_alert_dialog_set_buttons(dialog, buttons);
|
||||
gtk_alert_dialog_set_cancel_button(dialog, 0);
|
||||
gtk_alert_dialog_set_default_button(dialog, 1);
|
||||
g_signal_connect(dialog, "response", G_CALLBACK(&ManagerWindow::onGreeterResponse), this);
|
||||
gtk_alert_dialog_show(dialog, GTK_WINDOW(window_));
|
||||
gtk_alert_dialog_choose(dialog, GTK_WINDOW(window_), nullptr,
|
||||
&ManagerWindow::onGreeterChosen, this);
|
||||
g_object_unref(dialog);
|
||||
}
|
||||
|
||||
void askForce(const std::string& reason) {
|
||||
const std::string message =
|
||||
reason +
|
||||
"\n\nRedemarrer le gestionnaire d'affichage pour retrouver un ecran de connexion ? "
|
||||
"L'authentification est demandee par polkit ; la session courante sera fermee et "
|
||||
"les applications non enregistrees seront perdues.";
|
||||
GtkAlertDialog* dialog = gtk_alert_dialog_new("%s", message.c_str());
|
||||
const char* buttons[] = {"Annuler", "Redemarrer et fermer", nullptr};
|
||||
gtk_alert_dialog_set_buttons(dialog, buttons);
|
||||
gtk_alert_dialog_set_cancel_button(dialog, 0);
|
||||
gtk_alert_dialog_set_default_button(dialog, 0);
|
||||
gtk_alert_dialog_choose(dialog, GTK_WINDOW(window_), nullptr,
|
||||
&ManagerWindow::onForceChosen, this);
|
||||
g_object_unref(dialog);
|
||||
}
|
||||
|
||||
void goToGreeter(bool force) {
|
||||
setStatus(force ? "Redémarrage de l'écran de connexion…"
|
||||
: "Ouverture de l'écran de connexion…");
|
||||
flushPendingEvents();
|
||||
|
||||
const fws::GreeterOutcome outcome = fws::switchToGreeter(force);
|
||||
if (outcome.ok) {
|
||||
if (force) {
|
||||
setStatus("Écran de connexion redémarré.");
|
||||
} else if (!greeterIsCurrent_ && !greeterEntry_.empty()) {
|
||||
setStatus("Écran de connexion affiché : choisissez « " + greeterEntry_ +
|
||||
" » dans le sélecteur de session pour l'ouvrir.");
|
||||
} else {
|
||||
setStatus("Écran de connexion affiché ; la session reste ouverte.");
|
||||
}
|
||||
refreshRows();
|
||||
return;
|
||||
}
|
||||
|
||||
// Nothing has been closed yet: offer the destructive path explicitly
|
||||
// instead of dropping the user on a blank VT.
|
||||
if (outcome.forceRequired && !force) {
|
||||
askForce(outcome.error);
|
||||
setStatus("La session courante a été conservée.");
|
||||
return;
|
||||
}
|
||||
|
||||
showError(outcome.error);
|
||||
setStatus("Retour à l'écran de connexion impossible.");
|
||||
}
|
||||
|
||||
void showError(const std::string& message) {
|
||||
GtkAlertDialog* dialog = gtk_alert_dialog_new("%s", message.c_str());
|
||||
gtk_alert_dialog_show(dialog, GTK_WINDOW(window_));
|
||||
@@ -369,6 +506,9 @@ private:
|
||||
std::vector<RowWidgets> rows_;
|
||||
GSubprocess* pending_ = nullptr;
|
||||
bool busy_ = false;
|
||||
// Filled by askGreeter(): the greeter entry to name once it is on screen.
|
||||
std::string greeterEntry_;
|
||||
bool greeterIsCurrent_ = false;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in new issue
Block a user