widgets(terminal): ensure only one sigchild handler installed

This commit is contained in:
Tim Culverhouse 2024-06-12 06:36:07 -05:00
parent bf0828f9ef
commit cea5798db9
2 changed files with 16 additions and 11 deletions

View file

@ -49,19 +49,23 @@ pub fn spawn(self: *Command, allocator: std.mem.Allocator) !void {
_ = err catch {}; _ = err catch {};
} }
var act = posix.Sigaction{
.handler = .{ .handler = handleSigChild },
.mask = switch (builtin.os.tag) {
.macos => 0,
.linux => posix.empty_sigset,
else => @compileError("os not supported"),
},
.flags = 0,
};
try posix.sigaction(posix.SIG.CHLD, &act, null);
// we are the parent // we are the parent
self.pid = @intCast(pid); self.pid = @intCast(pid);
if (!Terminal.global_sigchild_installed) {
Terminal.global_sigchild_installed = true;
var act = posix.Sigaction{
.handler = .{ .handler = handleSigChild },
.mask = switch (builtin.os.tag) {
.macos => 0,
.linux => posix.empty_sigset,
else => @compileError("os not supported"),
},
.flags = 0,
};
try posix.sigaction(posix.SIG.CHLD, &act, null);
}
return; return;
} }

View file

@ -46,6 +46,7 @@ pub const InputEvent = union(enum) {
pub var global_vt_mutex: std.Thread.Mutex = .{}; pub var global_vt_mutex: std.Thread.Mutex = .{};
pub var global_vts: ?std.AutoHashMap(i32, *Terminal) = null; pub var global_vts: ?std.AutoHashMap(i32, *Terminal) = null;
pub var global_sigchild_installed: bool = false;
allocator: std.mem.Allocator, allocator: std.mem.Allocator,
scrollback_size: usize, scrollback_size: usize,