Commit e4cbac85 authored by David Edmundson's avatar David Edmundson
Browse files

Handle closeSession being called concurrently

Currently if hypothetically closeSession was called multiple times
before the async operation completed the first caller would never get a
reply and then be left hanging potentially forever.

This is unlikely to happen in real life given only the plasma shutdown
binary should be calling this and that's a unique application.


(cherry picked from commit 3754967b)
parent 74fef0a9
......@@ -95,10 +95,21 @@ void KSMServer::logout(int confirm, int sdtype, int sdmode)
bool KSMServer::closeSession()
{
qCDebug(KSMSERVER) << "Close session called. Current state is:" << state;
Q_ASSERT(calledFromDBus());
performLogout();
setDelayedReply(true);
m_performLogoutCall = message();
const QDBusMessage callerContext = message();
auto conn = QSharedPointer<QMetaObject::Connection>::create(QMetaObject::Connection());
*conn = connect(this, &KSMServer::logoutFinished, this, [callerContext, conn](bool sessionClosed) {
auto reply = callerContext.createReply(sessionClosed);
QDBusConnection::sessionBus().send(reply);
QObject::disconnect(*conn);
});
performLogout();
return false;
}
......@@ -366,12 +377,7 @@ void KSMServer::cancelShutdown(KSMClient *c)
m_kwinInterface->setState(KWinSessionState::Normal);
if (m_performLogoutCall.type() == QDBusMessage::MethodCallMessage) {
auto reply = m_performLogoutCall.createReply(false);
QDBusConnection::sessionBus().send(reply);
m_performLogoutCall = QDBusMessage();
}
emit logoutCancelled();
emit logoutFinished(false);
}
void KSMServer::startProtection()
......@@ -505,11 +511,7 @@ void KSMServer::completeKilling()
// shutdown is fully complete
void KSMServer::killingCompleted()
{
if (m_performLogoutCall.type() == QDBusMessage::MethodCallMessage) {
auto reply = m_performLogoutCall.createReply(true);
QDBusConnection::sessionBus().send(reply);
m_performLogoutCall = QDBusMessage();
}
emit logoutFinished(true);
qApp->quit();
}
......
......@@ -122,7 +122,7 @@ public:
void setupShortcuts();
Q_SIGNALS:
void logoutCancelled();
void logoutFinished(bool sessionClosed);
public Q_SLOTS:
......@@ -235,7 +235,6 @@ private:
WindowMap legacyWindows;
QDBusMessage m_performLogoutCall;
QDBusMessage m_restoreSessionCall;
// subSession stuff
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment