From c2ac98d194b6b74b30eba0fabec7d66ebf64f40c Mon Sep 17 00:00:00 2001 From: Aditya Alok Date: Sun, 10 May 2026 04:37:33 +0530 Subject: [PATCH] services/polkit: refactor authentication request queueing - Relying on `queuedRequests.size() == 1` is buggy as it allows newer requests to takeover the currently active one. - Now we rely on `bActiveFlow.value()` being `nullptr`. - Process requests linearly until we find a valid request to prevent deadlock. Signed-off-by: Aditya Alok --- changelog/next.md | 1 + src/services/polkit/agentimpl.cpp | 67 +++++++++++++++---------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/changelog/next.md b/changelog/next.md index aaeaf1cc..598ce17e 100644 --- a/changelog/next.md +++ b/changelog/next.md @@ -1,4 +1,5 @@ ## Bug Fixes +- Fixed newer polkit requests overtaking currently active one. - Fixed ScreencopyView not displaying when only lock surfaces are shown. - Fixed WlSessionLockSurface.visible crashing if accessed before backing surface creation. diff --git a/src/services/polkit/agentimpl.cpp b/src/services/polkit/agentimpl.cpp index 85c62b71..496b46ac 100644 --- a/src/services/polkit/agentimpl.cpp +++ b/src/services/polkit/agentimpl.cpp @@ -106,7 +106,7 @@ void PolkitAgentImpl::initiateAuthentication(AuthRequest* request) { this->queuedRequests.emplace_back(request); - if (this->queuedRequests.size() == 1) { + if (!this->bActiveFlow.value()) { this->activateAuthenticationRequest(); } } @@ -130,37 +130,39 @@ void PolkitAgentImpl::cancelAuthentication(AuthRequest* request) { } void PolkitAgentImpl::activateAuthenticationRequest() { - if (this->queuedRequests.empty()) return; + while (!this->queuedRequests.empty()) { + AuthRequest* req = this->queuedRequests.front(); + this->queuedRequests.pop_front(); + qCDebug(logPolkit) << "activating authentication request for action" << req->actionId + << ", cookie: " << req->cookie; + + QList identities; + for (auto& identity: req->identities) { + auto* obj = Identity::fromPolkitIdentity(identity); + if (obj) identities.append(obj); + } + if (identities.isEmpty()) { + qCWarning( + logPolkit + ) << "no supported identities available for authentication request, cancelling."; + req->cancel("Error requesting authentication: no supported identities available."); + delete req; + continue; + } + + this->bActiveFlow = new AuthFlow(req, std::move(identities)); + + QObject::connect( + this->bActiveFlow.value(), + &AuthFlow::isCompletedChanged, + this, + &PolkitAgentImpl::finishAuthenticationRequest + ); + + emit this->qmlAgent->authenticationRequestStarted(); - AuthRequest* req = this->queuedRequests.front(); - this->queuedRequests.pop_front(); - qCDebug(logPolkit) << "activating authentication request for action" << req->actionId - << ", cookie: " << req->cookie; - - QList identities; - for (auto& identity: req->identities) { - auto* obj = Identity::fromPolkitIdentity(identity); - if (obj) identities.append(obj); - } - if (identities.isEmpty()) { - qCWarning( - logPolkit - ) << "no supported identities available for authentication request, cancelling."; - req->cancel("Error requesting authentication: no supported identities available."); - delete req; return; } - - this->bActiveFlow = new AuthFlow(req, std::move(identities)); - - QObject::connect( - this->bActiveFlow.value(), - &AuthFlow::isCompletedChanged, - this, - &PolkitAgentImpl::finishAuthenticationRequest - ); - - emit this->qmlAgent->authenticationRequestStarted(); } void PolkitAgentImpl::finishAuthenticationRequest() { @@ -170,11 +172,8 @@ void PolkitAgentImpl::finishAuthenticationRequest() { << this->bActiveFlow.value()->actionId(); this->bActiveFlow.value()->deleteLater(); + this->bActiveFlow = nullptr; - if (!this->queuedRequests.empty()) { - this->activateAuthenticationRequest(); - } else { - this->bActiveFlow = nullptr; - } + this->activateAuthenticationRequest(); } } // namespace qs::service::polkit