From cea5798db92b2c5257df03469e22da92134ef15e Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Wed, 12 Jun 2024 06:36:07 -0500 Subject: [PATCH] widgets(terminal): ensure only one sigchild handler installed --- src/widgets/terminal/Command.zig | 26 +++++++++++++++----------- src/widgets/terminal/Terminal.zig | 1 + 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/widgets/terminal/Command.zig b/src/widgets/terminal/Command.zig index c61229a..e9e8dc8 100644 --- a/src/widgets/terminal/Command.zig +++ b/src/widgets/terminal/Command.zig @@ -49,19 +49,23 @@ pub fn spawn(self: *Command, allocator: std.mem.Allocator) !void { _ = 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 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; } diff --git a/src/widgets/terminal/Terminal.zig b/src/widgets/terminal/Terminal.zig index abf292c..7647a66 100644 --- a/src/widgets/terminal/Terminal.zig +++ b/src/widgets/terminal/Terminal.zig @@ -46,6 +46,7 @@ pub const InputEvent = union(enum) { pub var global_vt_mutex: std.Thread.Mutex = .{}; pub var global_vts: ?std.AutoHashMap(i32, *Terminal) = null; +pub var global_sigchild_installed: bool = false; allocator: std.mem.Allocator, scrollback_size: usize,