diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 00:57:44 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:27:20 -0300 |
| commit | 0de5fd5523faf4028b5c5e334367d28b4079aec3 (patch) | |
| tree | 5e059853da6a4a898291a429892cc66dd7ca31d9 /src/tui/tui.zig | |
| parent | e50c1b3fc928bf860bc6e91b0a2fea469f7e41e7 (diff) | |
| download | pardes-0de5fd5523faf4028b5c5e334367d28b4079aec3.tar.gz pardes-0de5fd5523faf4028b5c5e334367d28b4079aec3.zip | |
host_io: the shells a dead session left are one Adoptions table (Adopt's ask, adoptShell, a spawn's take, and the Adoption a terminal pane takes), where the tty and the window each kept the same three fields and the same adopt, adoptShell and spawn lookup
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/tui/tui.zig')
| -rw-r--r-- | src/tui/tui.zig | 51 |
1 files changed, 7 insertions, 44 deletions
diff --git a/src/tui/tui.zig b/src/tui/tui.zig index 5c16f1be..2a107dc4 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -1654,7 +1654,7 @@ fn localSession( _ = libc.close(pt.file.handle); slot.* = null; }; - for (sh.adoptions[0..sh.adoptions_len]) |a| _ = libc.close(a.fd); + for (sh.adoptions.list[0..sh.adoptions.len]) |a| _ = libc.close(a.fd); if (sh.lsp_task) |*t| { t.future.cancel(io); sh.lsp_task = null; @@ -1799,8 +1799,6 @@ fn clearNativeImages( kitty_handles.clearRetainingCapacity(); } -const Adoption = struct { pid: posix.pid_t, fd: posix.fd_t, pane: ?u8 }; - /// The daemon's thread: what it says, onto the loop's queue. fn deliverNote(ctx: *anyopaque, note: daemon.Note) void { const loop: *Loop = @ptrCast(@alignCast(ctx)); @@ -1849,9 +1847,7 @@ const Shell = struct { inotify_fd: c_int, /// Shells a dead session left (Adopt), each waiting for the spawn of /// the terminal pane made for it. - adoptions: [pardes.MAX_PANES]Adoption = undefined, - adoptions_len: usize = 0, - adopted: usize = 0, + adoptions: host_io.Adoptions = .{}, fs: ?*ninep_io.Listener = null, ptys: [pardes.MAX_PANES]?Pty = @splat(null), gens: [pardes.MAX_PANES]u32 = @splat(0), @@ -2086,13 +2082,9 @@ const Shell = struct { if (stub >= 0) daemon.refuseStub(stub, why); } - /// Adopt: the daemon is asked for the shells of sessions that died - /// holding them; each comes back (`adopted`) as a terminal pane here. fn adopt(ctx: ?*anyopaque, pane: u8) void { const s = of(ctx); - if (!daemon.kept()) return s.core.reportFailure(pane, "Adopt: no pardes daemon is keeping shells for this session"); - s.adopted = 0; - daemon.adopt(); + s.adoptions.ask(s.core, pane); } /// A client's own build is not the session's to say (its core's host @@ -2193,7 +2185,7 @@ const Shell = struct { for (rec.ptys[0..rec.nptys]) |k| { const pane = if (rec.fresh) null else s.core.panes[k.pane]; if (pane == null or !pane.?.isTerminal()) { - s.adoptShell(k.pid, k.fd); + s.adoptions.adoptShell(s.core, k.pid, k.fd); continue; } const file: std.Io.File = .{ .handle = k.fd, .flags = .{ .nonblocking = false } }; @@ -2254,31 +2246,6 @@ const Shell = struct { if (s.terms[core.view] == null) s.terms[core.view] = primary; } - /// One shell of a dead session (`pid` 0: the last of them was told). - fn adoptShell(s: *Shell, pid: posix.pid_t, fd: posix.fd_t) void { - const core = s.core; - if (pid == 0) { - var buf: [96]u8 = undefined; - return core.setMessage(core.active, if (s.adopted == 0) "Adopt: no shell of a session that died is waiting" else std.fmt.bufPrint(&buf, "Adopt: {d} shell{s} taken in; what they showed is gone", .{ s.adopted, if (s.adopted == 1) "" else "s" }) catch "Adopt: shells taken in"); - } - if (s.adoptions_len < s.adoptions.len) { - // A terminal pane, as the Term word makes one; its spawn takes - // this pty instead of forking a shell (`spawn`). - s.adoptions[s.adoptions_len] = .{ .pid = pid, .fd = fd, .pane = null }; - s.adoptions_len += 1; - if (core.adoptShell()) |id| { - s.adoptions[s.adoptions_len - 1].pane = id; - s.adopted += 1; - return; - } - s.adoptions_len -= 1; - } - // No room for it: its master goes, and the shell with this session. - _ = libc.close(fd); - var buf: [96]u8 = undefined; - core.setMessage(core.active, std.fmt.bufPrint(&buf, "Adopt: no room for shell {d}; it ends with this session", .{pid}) catch "Adopt: no room for a shell"); - } - fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { const s = of(ctx); // The wait is the 9P connections' turn with the core. A timeout (the @@ -2486,7 +2453,7 @@ const Shell = struct { return true; }, .attach => |a| s.attachTerminal(a.tty, a.stub, null), - .adopted => |a| s.adoptShell(a.pid, a.fd), + .adopted => |a| s.adoptions.adoptShell(s.core, a.pid, a.fd), .replica => |j| { s.peers.handed(j.fd, j.view); s.input_seen = true; @@ -2805,11 +2772,7 @@ const Shell = struct { fn spawn(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { const s = of(ctx); - for (s.adoptions[0..s.adoptions_len], 0..) |a, i| if (a.pane == pane) { - std.mem.copyForwards(Adoption, s.adoptions[i .. s.adoptions_len - 1], s.adoptions[i + 1 .. s.adoptions_len]); - s.adoptions_len -= 1; - return s.takeShell(pane, a); - }; + if (s.adoptions.take(pane)) |a| return s.takeShell(pane, a); // The new shell starts before a running one goes: one that cannot // start leaves the running one be (pty/ctl's exec). const running = s.ptys[pane] != null; @@ -2835,7 +2798,7 @@ const Shell = struct { /// An adopted shell, running already, as pane `pane`'s: told the size /// twice (a size it never had, then the pane's), which makes it redraw. - fn takeShell(s: *Shell, pane: u8, a: Adoption) void { + fn takeShell(s: *Shell, pane: u8, a: host_io.Adoption) void { closePty(s, pane); s.gens[pane] +%= 1; const file: std.Io.File = .{ .handle = a.fd, .flags = .{ .nonblocking = false } }; |
