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:
Mitchell Hashimoto
2025-01-24 13:53:45 -08:00
committed by GitHub
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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);