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,6 +49,11 @@ pub fn spawn(self: *Command, allocator: std.mem.Allocator) !void {
_ = err catch {}; _ = err catch {};
} }
// we are the parent
self.pid = @intCast(pid);
if (!Terminal.global_sigchild_installed) {
Terminal.global_sigchild_installed = true;
var act = posix.Sigaction{ var act = posix.Sigaction{
.handler = .{ .handler = handleSigChild }, .handler = .{ .handler = handleSigChild },
.mask = switch (builtin.os.tag) { .mask = switch (builtin.os.tag) {
@ -59,9 +64,8 @@ pub fn spawn(self: *Command, allocator: std.mem.Allocator) !void {
.flags = 0, .flags = 0,
}; };
try posix.sigaction(posix.SIG.CHLD, &act, null); try posix.sigaction(posix.SIG.CHLD, &act, null);
}
// we are the parent
self.pid = @intCast(pid);
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,