git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit0c811a8afe899786125a35f68b58e773018268b4
parent18b6d1a5f3
authorIsaac Freund <[email protected]>
date2025-01-07 11:00
Xwayland: don't inherit rlimit changes from river

(cherry picked from commit 543697847f2167152ae25f775f39541591b8d020)

 river/main.zig | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/river/main.zig b/river/main.zig
index f466275..d290c40 100644
--- a/river/main.zig
+++ b/river/main.zig
@@ -101,7 +101,7 @@ pub fn main() anyerror!void {
             }
         }
     }
-    const enable_xwayland = !result.flags.@"no-xwayland";
+    const runtime_xwayland = !result.flags.@"no-xwayland";
     const startup_command = blk: {
         if (result.flags.c) |command| {
             break :blk try util.gpa.dupeZ(u8, command);
@@ -112,17 +112,25 @@ pub fn main() anyerror!void {
 
     log.info("river version {s}, initializing server", .{build_options.version});
 
-    process.setup();
-
     river_init_wlroots_log(switch (runtime_log_level) {
         .debug => .debug,
         .info => .info,
         .warn, .err => .err,
     });
 
-    try server.init(enable_xwayland);
+    try server.init(runtime_xwayland);
     defer server.deinit();
 
+    // wlroots starts the Xwayland process from an idle event source, the reasoning being that
+    // this gives the compositor time to set up event listeners before Xwayland is actually
+    // started. We want Xwayland to be started by wlroots before we modify our rlimits in
+    // process.setup() since wlroots does not offer a way for us to reset the rlimit post-fork.
+    if (build_options.xwayland and runtime_xwayland) {
+        server.wl_server.getEventLoop().dispatchIdle();
+    }
+
+    process.setup();
+
     try server.start();
 
     // Run the child in a new process group so that we can send SIGTERM to all