Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
- Fixed missing/wrong change signals on various properties.
- Fixed session lock crashes on sleep, wake, DPMS, and unlocking.
- QsWindow.updatesEnabled makes sure windows are redrawn when set to true.
- Fixed the polkit agent failing to register when running outside a session cgroup, such as a systemd user service, by resolving the session from XDG_SESSION_ID.
31 changes: 31 additions & 0 deletions src/services/polkit/listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
#include <polkit/polkit.h>
#include <polkit/polkittypes.h>
#include <polkitagent/polkitagent.h>
#include <qbytearray.h>
#include <qlogging.h>
#include <qloggingcategory.h>
#include <qstring.h>
#include <qtenvironmentvariables.h>
#include <unistd.h>

#include "../../core/logcat.hpp"
Expand Down Expand Up @@ -93,6 +96,34 @@ void qs_polkit_agent_register(QsPolkitAgent* agent, const char* path) {
return;
}

const auto sessionId = qEnvironmentVariable("XDG_SESSION_ID");
if (!sessionId.isEmpty()) {
const auto sessionIdUtf8 = sessionId.toUtf8();
auto* subject = polkit_unix_session_new(sessionIdUtf8.constData());
if (subject != nullptr) {
GError* error = nullptr;
agent->registration_handle = polkit_agent_listener_register(
POLKIT_AGENT_LISTENER(agent),
POLKIT_AGENT_REGISTER_FLAGS_NONE,
subject,
path,
nullptr,
&error
);
g_object_unref(subject);

if (error != nullptr) {
qCWarning(logPolkitListener) << "failed to register listener:" << error->message;
g_clear_error(&error);
agent->cb->registerComplete(false);
return;
}

agent->cb->registerComplete(true);
return;
}
}

auto* data = new RegisterCbData {.agent = GObjectRef(agent), .path = path};
polkit_unix_session_new_for_process(getpid(), nullptr, &qs_polkit_agent_register_cb, data);
}
Expand Down
Loading