mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-13 23:36:09 +03:00
Ignore SIGPIPE (#5360)
Fixes #5359 The comments explain what's going on. Longer term we should adjust our termio/exec to avoid the SIGPIPE but its still possible (i.e. that thread crashes) to happen so we should be robust to it.
This commit is contained in:
@ -111,6 +111,9 @@ pub const GlobalState = struct {
|
||||
}
|
||||
}
|
||||
|
||||
// Setup our signal handlers before logging
|
||||
initSignals();
|
||||
|
||||
// Output some debug information right away
|
||||
std.log.info("ghostty version={s}", .{build_config.version_string});
|
||||
std.log.info("ghostty build optimize={s}", .{build_config.mode_string});
|
||||
@ -175,6 +178,28 @@ pub const GlobalState = struct {
|
||||
_ = value.deinit();
|
||||
}
|
||||
}
|
||||
|
||||
fn initSignals() void {
|
||||
// Only posix systems.
|
||||
if (comptime builtin.os.tag == .windows) return;
|
||||
|
||||
const p = std.posix;
|
||||
|
||||
var sa: p.Sigaction = .{
|
||||
.handler = .{ .handler = p.SIG.IGN },
|
||||
.mask = p.empty_sigset,
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
// We ignore SIGPIPE because it is a common signal we may get
|
||||
// due to how we implement termio. When a terminal is closed we
|
||||
// often write to a broken pipe to exit the read thread. This should
|
||||
// be fixed one day but for now this helps make this a bit more
|
||||
// robust.
|
||||
p.sigaction(p.SIG.PIPE, &sa, null) catch |err| {
|
||||
std.log.warn("failed to ignore SIGPIPE err={}", .{err});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/// Maintains the Unix resource limits that we set for our process. This
|
||||
|
@ -201,6 +201,7 @@ const PosixPty = struct {
|
||||
try posix.sigaction(posix.SIG.HUP, &sa, null);
|
||||
try posix.sigaction(posix.SIG.ILL, &sa, null);
|
||||
try posix.sigaction(posix.SIG.INT, &sa, null);
|
||||
try posix.sigaction(posix.SIG.PIPE, &sa, null);
|
||||
try posix.sigaction(posix.SIG.SEGV, &sa, null);
|
||||
try posix.sigaction(posix.SIG.TRAP, &sa, null);
|
||||
try posix.sigaction(posix.SIG.TERM, &sa, null);
|
||||
|
Reference in New Issue
Block a user