Skip to content

Commit

Permalink
feat: support treeland crash recovery
Browse files Browse the repository at this point in the history
When greeter restarts, resend logged in user information

Log:
  • Loading branch information
justforlxz committed May 17, 2024
1 parent 5600193 commit 3405f9a
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 8 deletions.
4 changes: 3 additions & 1 deletion data/interfaces/org.freedesktop.DisplayManager.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection
1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.DisplayManager">
Expand Down Expand Up @@ -38,5 +38,7 @@
</property>
<property type="ao" name="Sessions" access="read">
</property>
<property type="o" name="LastSession" access="read">
</property>
</interface>
</node>
4 changes: 0 additions & 4 deletions src/common/Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ namespace DDM {
LoginSucceeded,
LoginFailed,
InformationMessage,
CreateWaylandSocket,
DeleteWaylandSocket,
WaylandSocketCreated,
WaylandSocketDeleted,
UserActivateMessage,
SwitchToGreeter,
};
Expand Down
4 changes: 3 additions & 1 deletion src/daemon/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,10 @@ namespace DDM {
stateConfig.Last.Session.setDefault();
stateConfig.save();

if (m_socket)
if (m_socket) {
emit loginSucceeded(m_socket, user);
daemonApp->displayManager()->setLastSession(auth->sessionId());
}
}
m_socket = nullptr;
}
Expand Down
4 changes: 4 additions & 0 deletions src/daemon/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ namespace DDM {
void switchToUser(const QString &user);
void activateUser(const QString &user);

QVector<Auth*> loginedSession() const {
return m_auths;
}

public slots:
bool start();
void stop();
Expand Down
16 changes: 16 additions & 0 deletions src/daemon/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ namespace DDM {
// remove from list
m_sessions.removeAll(session);

if (name == m_lastSession.path()) {
m_lastSession = ObjectPath();
Q_EMIT LastSessionChanged(m_lastSession);
}

// get object path
ObjectPath path = ObjectPath(session->Path());

Expand All @@ -129,6 +134,17 @@ namespace DDM {
}
}

void DisplayManager::setLastSession(const QString &name) {
// find session
for (DisplayManagerSession *session: m_sessions) {
if (session->Name() == name) {
m_lastSession = ObjectPath(session->Path());
Q_EMIT LastSessionChanged(m_lastSession);
break;
}
}
}

DisplayManagerSeat::DisplayManagerSeat(const QString &name, QObject *parent)
: QObject(parent), m_name(name), m_path(DISPLAYMANAGER_SEAT_PATH + name.mid(4)) {
// create adaptor
Expand Down
7 changes: 7 additions & 0 deletions src/daemon/DisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace DDM {
Q_DISABLE_COPY(DisplayManager)
Q_PROPERTY(QList<QDBusObjectPath> Seats READ Seats CONSTANT)
Q_PROPERTY(QList<QDBusObjectPath> Sessions READ Sessions CONSTANT)
Q_PROPERTY(QDBusObjectPath LastSession READ LastSession NOTIFY LastSessionChanged CONSTANT)
public:
DisplayManager(QObject *parent = 0);

Expand All @@ -48,22 +49,28 @@ namespace DDM {

ObjectPathList Seats() const;
ObjectPathList Sessions(DisplayManagerSeat *seat = nullptr) const;
QDBusObjectPath LastSession() const {
return m_lastSession;
}

public slots:
void AddSeat(const QString &name);
void RemoveSeat(const QString &name);
void AddSession(const QString &name, const QString &seat, const QString &user);
void RemoveSession(const QString &name);
void setLastSession(const QString &session);

signals:
void SeatAdded(ObjectPath seat);
void SeatRemoved(ObjectPath seat);
void SessionAdded(ObjectPath session);
void SessionRemoved(ObjectPath session);
void LastSessionChanged(ObjectPath session);

private:
QList<DisplayManagerSeat *> m_seats;
QList<DisplayManagerSession *> m_sessions;
QDBusObjectPath m_lastSession;
};

/***************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/SingleWaylandDisplayServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ SingleWaylandDisplayServer::SingleWaylandDisplayServer(SocketServer *socketServe
// log message
qDebug() << "Socket server started.";

connect(m_socketServer, &SocketServer::connected, this, [this](QLocalSocket *socket) {
connect(m_socketServer, &SocketServer::connected, this, [this, parent](QLocalSocket *socket) {
m_greeterSockets << socket;
});
connect(m_socketServer, &SocketServer::disconnected, this, [this](QLocalSocket *socket) {
Expand Down
21 changes: 20 additions & 1 deletion src/helper/singlewaylandhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

SingleWaylandHelper::SingleWaylandHelper(QObject *parent)
: QObject(parent)
, m_wCompositorCrashCount(0)
, m_maxCrashCountLimit(3)
{}

bool SingleWaylandHelper::start(const QString &compositor, const QString &cmd)
Expand Down Expand Up @@ -37,7 +39,24 @@ bool SingleWaylandHelper::start(const QString &compositor, const QString &cmd)
});
connect(m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
m_process, [this](int exitCode, QProcess::ExitStatus exitStatus) {
qDebug() << "TreeLand stopped. It will restart." << exitCode << exitStatus;
qDebug() << "kwin_wayland exit with exitCode:" << exitCode << exitStatus;
if (exitCode == 0) {
qApp->quit();
return;
} else if (exitCode == 133) {
m_wCompositorCrashCount = 0;
} else {
m_wCompositorCrashCount++;
}

if (m_wCompositorCrashCount > m_maxCrashCountLimit) {
qApp->quit();
return;
}

qWarning() << "WAYLAND Restart count: " << QByteArray::number(m_wCompositorCrashCount);

// restart
m_process->start();
});

Expand Down
2 changes: 2 additions & 0 deletions src/helper/singlewaylandhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ class SingleWaylandHelper : public QObject {

private:
QProcess *m_process;
int m_wCompositorCrashCount;
int m_maxCrashCountLimit;
};

0 comments on commit 3405f9a

Please sign in to comment.