Skip to content

Commit c2ac98d

Browse files
committed
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 <dev.aditya.alok@gmail.com>
1 parent 7d1c9a9 commit c2ac98d

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

changelog/next.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Bug Fixes
22

3+
- Fixed newer polkit requests overtaking currently active one.
34
- Fixed ScreencopyView not displaying when only lock surfaces are shown.
45
- Fixed WlSessionLockSurface.visible crashing if accessed before backing surface creation.

src/services/polkit/agentimpl.cpp

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void PolkitAgentImpl::initiateAuthentication(AuthRequest* request) {
106106

107107
this->queuedRequests.emplace_back(request);
108108

109-
if (this->queuedRequests.size() == 1) {
109+
if (!this->bActiveFlow.value()) {
110110
this->activateAuthenticationRequest();
111111
}
112112
}
@@ -130,37 +130,39 @@ void PolkitAgentImpl::cancelAuthentication(AuthRequest* request) {
130130
}
131131

132132
void PolkitAgentImpl::activateAuthenticationRequest() {
133-
if (this->queuedRequests.empty()) return;
133+
while (!this->queuedRequests.empty()) {
134+
AuthRequest* req = this->queuedRequests.front();
135+
this->queuedRequests.pop_front();
136+
qCDebug(logPolkit) << "activating authentication request for action" << req->actionId
137+
<< ", cookie: " << req->cookie;
138+
139+
QList<Identity*> identities;
140+
for (auto& identity: req->identities) {
141+
auto* obj = Identity::fromPolkitIdentity(identity);
142+
if (obj) identities.append(obj);
143+
}
144+
if (identities.isEmpty()) {
145+
qCWarning(
146+
logPolkit
147+
) << "no supported identities available for authentication request, cancelling.";
148+
req->cancel("Error requesting authentication: no supported identities available.");
149+
delete req;
150+
continue;
151+
}
152+
153+
this->bActiveFlow = new AuthFlow(req, std::move(identities));
154+
155+
QObject::connect(
156+
this->bActiveFlow.value(),
157+
&AuthFlow::isCompletedChanged,
158+
this,
159+
&PolkitAgentImpl::finishAuthenticationRequest
160+
);
161+
162+
emit this->qmlAgent->authenticationRequestStarted();
134163

135-
AuthRequest* req = this->queuedRequests.front();
136-
this->queuedRequests.pop_front();
137-
qCDebug(logPolkit) << "activating authentication request for action" << req->actionId
138-
<< ", cookie: " << req->cookie;
139-
140-
QList<Identity*> identities;
141-
for (auto& identity: req->identities) {
142-
auto* obj = Identity::fromPolkitIdentity(identity);
143-
if (obj) identities.append(obj);
144-
}
145-
if (identities.isEmpty()) {
146-
qCWarning(
147-
logPolkit
148-
) << "no supported identities available for authentication request, cancelling.";
149-
req->cancel("Error requesting authentication: no supported identities available.");
150-
delete req;
151164
return;
152165
}
153-
154-
this->bActiveFlow = new AuthFlow(req, std::move(identities));
155-
156-
QObject::connect(
157-
this->bActiveFlow.value(),
158-
&AuthFlow::isCompletedChanged,
159-
this,
160-
&PolkitAgentImpl::finishAuthenticationRequest
161-
);
162-
163-
emit this->qmlAgent->authenticationRequestStarted();
164166
}
165167

166168
void PolkitAgentImpl::finishAuthenticationRequest() {
@@ -170,11 +172,8 @@ void PolkitAgentImpl::finishAuthenticationRequest() {
170172
<< this->bActiveFlow.value()->actionId();
171173

172174
this->bActiveFlow.value()->deleteLater();
175+
this->bActiveFlow = nullptr;
173176

174-
if (!this->queuedRequests.empty()) {
175-
this->activateAuthenticationRequest();
176-
} else {
177-
this->bActiveFlow = nullptr;
178-
}
177+
this->activateAuthenticationRequest();
179178
}
180179
} // namespace qs::service::polkit

0 commit comments

Comments
 (0)