diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 00:30:19 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:40:44 -0300 |
| commit | 7ca4524a4cedfeddd6ffa4bcf4eb7465076d2d7d (patch) | |
| tree | 110cb1ae497477bee9c52367eeaa23a90c050001 /src/gui/gui.zig | |
| parent | bfa624697612693a4a9e8596f5f96ffc8f84bf87 (diff) | |
| download | pardes-7ca4524a4cedfeddd6ffa4bcf4eb7465076d2d7d.tar.gz pardes-7ca4524a4cedfeddd6ffa4bcf4eb7465076d2d7d.zip | |
gui: a closed shell goes to host_io.retireShell as the tui's and macOS's do, the window's own retired list gone (its slots, the reap on every spawn and reconcile, the loop's 16 ms poll while one waited); exit now waits out a shell's 100 ms grace (host_io.waitRetired) where it killed it at once, so a shell that saves on its hangup gets to, and one that ignores it is still killed and reaped before the window exits
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/gui/gui.zig')
| -rw-r--r-- | src/gui/gui.zig | 54 |
1 files changed, 8 insertions, 46 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 1bc8b959..edf8347a 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -836,9 +836,6 @@ const Pty = struct { cmd: host_io.CommandWatch = .{}, }; - -const RetiredShell = struct { pid: libc.pid_t = 0, kill_at: i64 = 0 }; - const Queue = host_io.Inbox; /// Wakes a blocking SDL_WaitEventTimeout from another thread: a push to @@ -1000,7 +997,6 @@ test "GUI PTY reader delivers a real shell tail before EOF and joins on close" { shell.ptys = &ptys; shell.gens = &gens; shell.queue = &queue; - shell.retired_shells = @splat(.{}); defer shell.shutdownPtys(); const rcs: host_io.Shell.PromptFiles = .{}; const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80, null); @@ -1052,7 +1048,6 @@ test "GUI PTY Restore joins a real reader waiting for queue space" { shell.ptys = &ptys; shell.gens = &gens; shell.queue = &queue; - shell.retired_shells = @splat(.{}); defer shell.shutdownPtys(); const rcs: host_io.Shell.PromptFiles = .{}; const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80, null); @@ -1081,7 +1076,7 @@ test "GUI PTY Restore joins a real reader waiting for queue space" { try std.testing.expectEqualStrings("fresh", batch.items[0].output.bytes); } -test "GUI PTY deletion joins an idle reader and retains only its owned child for reaping" { +test "GUI PTY deletion joins an idle reader and its shell is reaped by exit" { const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .tty_only = true }); defer core.deinit(); @@ -1095,7 +1090,6 @@ test "GUI PTY deletion joins an idle reader and retains only its owned child for shell.ptys = &ptys; shell.gens = &gens; shell.queue = &queue; - shell.retired_shells = @splat(.{}); defer shell.shutdownPtys(); const rcs: host_io.Shell.PromptFiles = .{}; const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80, null); @@ -1107,7 +1101,6 @@ test "GUI PTY deletion joins an idle reader and retains only its owned child for try std.testing.expectEqual(@as(usize, 0), queue.waiting); try std.testing.expectEqual(@as(usize, 0), queue.take().len); try std.testing.expectEqual(@as(c_int, -1), libc.fcntl(child.file.handle, libc.F.GETFD)); - for (shell.retired_shells) |retired| try std.testing.expect(retired.pid == 0 or retired.pid == child.pid); shell.shutdownPtys(); try std.testing.expectEqual(@as(libc.pid_t, -1), libc.waitpid(child.pid, null, libc.W.NOHANG)); try std.testing.expectEqual(libc.E.CHILD, libc.errno(-1)); @@ -1158,7 +1151,6 @@ test "GUI completion failure survives backlog and leaves the document unchanged" shell.lsp_allocator = gpa; shell.gens = &gens; shell.ptys = &ptys; - shell.retired_shells = @splat(.{}); shell.drainQueue(); try std.testing.expect(core.lsp_wait == null); try std.testing.expectEqualStrings("abc", pane.file.?.content); @@ -3733,7 +3725,6 @@ const Shell = struct { presented: bool = false, skipped_presents: u8 = 0, surface: ?*const pardes.Surface = null, - retired_shells: [pardes.MAX_PANES]RetiredShell = @splat(.{}), /// PARDES_TEST_CLOCK's virtual time (host_io.testClock), in test mode. test_clock: ?u64 = null, /// The display rate a virtual clock stands in for (PARDES_TEST_HZ). @@ -3764,11 +3755,6 @@ const Shell = struct { took_input: bool = false, held: ?c.SDL_Event = null, - fn reap(s: *Shell) void { - const now = std.Io.Clock.awake.now(s.queue.io).toMilliseconds(); - for (&s.retired_shells) |*child| host_io.reapRetired(&child.pid, &child.kill_at, now); - } - fn closePaneShell(ctx: ?*anyopaque, pane: u8) void { shellOf(ctx).closePty(pane); } @@ -3784,41 +3770,21 @@ const Shell = struct { } _ = libc.close(pt.fd); daemon.closed(pt.pid); - var pid = pt.pid; + host_io.retireShell(pt.pid); s.ptys[pane] = null; - const now = std.Io.Clock.awake.now(s.queue.io).toMilliseconds(); - var kill_at: i64 = 0; - host_io.reapRetired(&pid, &kill_at, now); - if (pid == 0) return; - _ = libc.kill(pid, libc.SIG.HUP); - for (&s.retired_shells) |*child| if (child.pid == 0) { - child.* = .{ .pid = pid, .kill_at = now + 100 }; - return; - }; - // No room to wait for it here: a slot kept for it would refuse the - // next shell spawned into this pane until it was reaped. - host_io.retireShell(pid); } fn stopPtys(s: *Shell) void { for (0..s.ptys.len) |pane| s.closePty(@intCast(pane)); for (s.gens) |*gen| gen.* +%= 1; - s.reap(); } fn shutdownPtys(s: *Shell) void { s.stopPtys(); - for (s.retired_shells) |child| if (child.pid > 0) { - _ = libc.kill(child.pid, libc.SIG.KILL); - }; - for (&s.retired_shells) |*child| if (child.pid > 0) { - while (libc.waitpid(child.pid, null, 0) < 0 and libc.errno(-1) == .INTR) {} - child.* = .{}; - }; + host_io.waitRetired(); } fn reconcilePtys(s: *Shell) void { - s.reap(); for (s.ptys, 0..) |slot, pane| if (slot) |pt| { const current = s.core.panes[pane]; if (current == null or current.?.serial != pt.serial or !current.?.isTerminal()) @@ -4251,14 +4217,11 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { // shell's queue raises for a terminal's output, a completion, a file // system request. What the shell moves or times itself polls every // frame: a smooth scroll, a gamepad's sticks, the test stdin feed, - // a post chain that moves on its own (ShaderAnimation), - // a retired shell waiting to be killed, a present to retry. A - // minimized window sleeps through the core's animation too: nothing - // shows it, and it is caught up at once when the window is back. - const retiring = for (s.retired_shells) |child| { - if (child.kill_at != 0) break true; - } else false; - const polls = g.scroll_lag != 0 or g.scroll_delta != 0 or g.scroll_notch != 0 or g.glide.moving() or g.gamepad != null or s.test_mode or core.needs_frame or retiring or + // a post chain that moves on its own (ShaderAnimation), a present + // to retry. A minimized window sleeps through the core's animation + // too: nothing shows it, and it is caught up at once when the window + // is back. + const polls = g.scroll_lag != 0 or g.scroll_delta != 0 or g.scroll_notch != 0 or g.glide.moving() or g.gamepad != null or s.test_mode or core.needs_frame or g.post.animating(core.settings.shader_animation); const minimized = !s.test_mode and c.SDL_GetWindowFlags(g.window) & (c.SDL_WINDOW_MINIMIZED | c.SDL_WINDOW_OCCLUDED) != 0; // A latency trace is fed on stdin, whose poll below paces the loop: @@ -4722,7 +4685,6 @@ fn guiNow(ctx: ?*anyopaque) u64 { fn spawnPane(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { const s = shellOf(ctx); - s.reap(); if (s.adoptions.take(pane)) |a| return takeShell(s, pane, a); // The new shell starts before a running one goes: one that cannot // start leaves the running one be (pty/ctl's exec). |
