From 600fd2e73cbf55c1393061d4b74c4fba5d3f16ff Mon Sep 17 00:00:00 2001 From: shironeko Date: Mon, 1 Aug 2022 17:11:26 -0400 Subject: river: ignore SIGPIPE to avoid weird exits When river or wlroots write to a closed socket it could generate SIGPIPE causing the whole desktop to seemingly "crash" with no error log of any kind. So we ignore the SIGPIPE and just let the write fail with EPIPE to be handled normally. --- river/main.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/river/main.zig b/river/main.zig index b0e6579..53a17e5 100644 --- a/river/main.zig +++ b/river/main.zig @@ -41,7 +41,18 @@ const usage: []const u8 = pub var server: Server = undefined; +fn sa_handler(_: c_int) callconv(.C) void {} + pub fn main() anyerror!void { + // ignore SIGPIPE so we don't get killed when socket unexpectedly closes (thanks xwayland) + // use our own handler instead of SIG_IGN so we don't leak this when execve() + const act = os.Sigaction{ + .handler = .{ .handler = sa_handler }, + .mask = os.empty_sigset, + .flags = 0, + }; + os.sigaction(os.SIG.PIPE, &act, null); + // This line is here because of https://github.com/ziglang/zig/issues/7807 const argv: [][*:0]const u8 = os.argv; const result = flags.parse(argv[1..], &[_]flags.Flag{ -- cgit v1.2.3