RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
freebsd fix
oxydizer8fe5440b5c24
diff --git a/src/polkit/agent.zig b/src/polkit/agent.zigindex a2384e0..9e4d641 100644--- a/src/polkit/agent.zig+++ b/src/polkit/agent.zig@@ -90,7 +90,7 @@ pub const Agent = struct {};self.pump_timer = try loop.addTimer(*Agent, pump, self);errdefer self.pump_timer.?.remove();- if (nonempty(environ.getPosix(if (activation.isTruthy(environ.getPosix("REDIWM_FORCE_POLKIT"))) "XDG_SESSION_ID" else "REDIWM_LOGIN_SESSION"))) |id| self.session_id = try allocator.dupe(u8, id);+ if (nonempty(environ.getPosix(if (activation.isTruthy(environ.getPosix("REDIWM_FORCE_POLKIT"))) "XDG_SESSION_ID" else "REDIWM_LOGIN_SESSION"))) |id| self.session_id = try allocator.dupe(u8, login.polkitSessionId(id));errdefer if (self.session_id) |id| allocator.free(id);inline for (.{ "BeginAuthentication", "CancelAuthentication" }) |member| try conn.register(.{.path = agent_path,@@ -220,7 +220,7 @@ pub const Agent = struct {const msg = result catch |err| return self.unavailable(err);const id = login.readSessionId(msg) catch |err| return self.unavailable(err);if (id.len == 0) return self.unavailable(error.NoSession);- self.session_id = self.allocator.dupe(u8, id) catch |err| return self.unavailable(err);+ self.session_id = self.allocator.dupe(u8, login.polkitSessionId(id)) catch |err| return self.unavailable(err);self.queryOwner();}@@ -296,6 +296,10 @@ pub const Agent = struct {return;}const msg = result catch |err| return self.unavailable(err);+ if (msg.kind == .error_reply) {+ var text = msg.body;+ log.warn("registration refused: {s}: {s}", .{ msg.headers.error_name orelse "?", text.string() catch "" });+ }// A bus-generated refusal must not cause an unbounded retry loop._ = returned(msg, "") catch |err| return self.unavailable(err);// A reply from an unrelated sender cannot validate this owner.diff --git a/src/session/login_manager.zig b/src/session/login_manager.zigindex 74facf8..ef111d6 100644--- a/src/session/login_manager.zig+++ b/src/session/login_manager.zig@@ -39,6 +39,7 @@ pub fn Service(comptime implementation: type) type {pub const changedOwner = implementation.changedOwner;pub const readSessionPath = implementation.readSessionPath;pub const readSessionId = implementation.readSessionId;+ pub const polkitSessionId = implementation.polkitSessionId;pub const readApi = implementation.readApi;pub const actionError = implementation.actionError;pub const owns_session = implementation.owns_session;@@ -57,6 +58,7 @@ pub const owner_match = Native.owner_match;pub const changedOwner = Native.changedOwner;pub const readSessionPath = Native.readSessionPath;pub const readSessionId = Native.readSessionId;+pub const polkitSessionId = Native.polkitSessionId;pub const readApi = Native.readApi;pub const actionError = Native.actionError;pub const owns_session = Native.owns_session;diff --git a/src/session/login_manager/consolekit.zig b/src/session/login_manager/consolekit.zigindex 0789f1b..6bc5176 100644--- a/src/session/login_manager/consolekit.zig+++ b/src/session/login_manager/consolekit.zig@@ -1,5 +1,5 @@//! ConsoleKit2 2.x. Protocol checked against upstream's Manager/Session XML.-//! Session identities are object paths (also what polkit's unix-session uses).+//! Session identities are object paths; polkit's unix-session takes the short id.const std = @import("std");const dbus = @import("dbus");const wire = dbus.wire;@@ -10,6 +10,7 @@ const manager = name ++ ".Manager";const session = name ++ ".Session";const bus = "org.freedesktop.DBus";const bus_path = "/org/freedesktop/DBus";+const session_prefix = "/org/freedesktop/ConsoleKit/";pub const owns_session = true;pub const login = @import("consolekit_login.zig").login;pub const conflict = @import("consolekit_login.zig").conflict;@@ -28,7 +29,7 @@ pub fn encode(request: types.Request, body: *wire.Writer) !types.Target {target.member = "GetSession";target.signature = "s";// GetId returns a path, but Manager.GetSession takes the short id.- const prefix = "/org/freedesktop/ConsoleKit/";+ const prefix = session_prefix;if (!std.mem.startsWith(u8, id, prefix) or id.len == prefix.len or std.mem.indexOfScalar(u8, id[prefix.len..], '/') != null) return error.InvalidSession;try body.string(id[prefix.len..]);},@@ -155,6 +156,13 @@ pub fn readSessionPath(msg: wire.Message) ![]const u8 {}pub const readSessionId = readSessionPath;+/// polkitd's ConsoleKit monitor reads CK2's database, which names sessions+/// "Session3"; registering an agent for the object path is refused as "the+/// session the caller is in differs" (polkit 128, FreeBSD 15.1).+pub fn polkitSessionId(id: []const u8) []const u8 {+ return if (std.mem.startsWith(u8, id, session_prefix)) id[session_prefix.len..] else id;+}+pub fn readApi(msg: wire.Message) types.Api {if (msg.kind != .method_return) return .{};var body = msg.body;diff --git a/src/session/login_manager/consolekit_tests.zig b/src/session/login_manager/consolekit_tests.zigindex f8167ad..2aa35c8 100644--- a/src/session/login_manager/consolekit_tests.zig+++ b/src/session/login_manager/consolekit_tests.zig@@ -41,4 +41,6 @@ test "ConsoleKit identity stays an object path for polkit, manager receives shortry reply.objectPath(path);const msg: dbus.wire.Message = .{ .kind = .method_return, .serial = 1, .headers = .{ .signature = "o" }, .body = .{ .bytes = reply.bytes.items } };try t.expectEqualStrings(path, try login.readSessionId(msg));+ try t.expectEqualStrings("Session9", login.polkitSessionId(path));+ try t.expectEqualStrings("Session9", login.polkitSessionId("Session9"));}diff --git a/src/session/login_manager/logind.zig b/src/session/login_manager/logind.zigindex 30039e3..b69b10d 100644--- a/src/session/login_manager/logind.zig+++ b/src/session/login_manager/logind.zig@@ -156,6 +156,11 @@ pub fn readSessionId(msg: wire.Message) ![]const u8 {return body.string();}+/// logind session ids are already what polkit's unix-session takes.+pub fn polkitSessionId(id: []const u8) []const u8 {+ return id;+}+pub fn readApi(msg: wire.Message) types.Api {if (msg.kind != .method_return) return .{};var body = msg.body;