a modern tui library written in zig

widgets(terminal): ensure only one sigchild handler installed

+16 -11
+15 -11
src/widgets/terminal/Command.zig
··· 49 _ = err catch {}; 50 } 51 52 - var act = posix.Sigaction{ 53 - .handler = .{ .handler = handleSigChild }, 54 - .mask = switch (builtin.os.tag) { 55 - .macos => 0, 56 - .linux => posix.empty_sigset, 57 - else => @compileError("os not supported"), 58 - }, 59 - .flags = 0, 60 - }; 61 - try posix.sigaction(posix.SIG.CHLD, &act, null); 62 - 63 // we are the parent 64 self.pid = @intCast(pid); 65 return; 66 } 67
··· 49 _ = err catch {}; 50 } 51 52 // we are the parent 53 self.pid = @intCast(pid); 54 + 55 + if (!Terminal.global_sigchild_installed) { 56 + Terminal.global_sigchild_installed = true; 57 + var act = posix.Sigaction{ 58 + .handler = .{ .handler = handleSigChild }, 59 + .mask = switch (builtin.os.tag) { 60 + .macos => 0, 61 + .linux => posix.empty_sigset, 62 + else => @compileError("os not supported"), 63 + }, 64 + .flags = 0, 65 + }; 66 + try posix.sigaction(posix.SIG.CHLD, &act, null); 67 + } 68 + 69 return; 70 } 71
+1
src/widgets/terminal/Terminal.zig
··· 46 47 pub var global_vt_mutex: std.Thread.Mutex = .{}; 48 pub var global_vts: ?std.AutoHashMap(i32, *Terminal) = null; 49 50 allocator: std.mem.Allocator, 51 scrollback_size: usize,
··· 46 47 pub var global_vt_mutex: std.Thread.Mutex = .{}; 48 pub var global_vts: ?std.AutoHashMap(i32, *Terminal) = null; 49 + pub var global_sigchild_installed: bool = false; 50 51 allocator: std.mem.Allocator, 52 scrollback_size: usize,