summaryrefslogtreecommitdiff
path: root/src/host_io.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 00:30:19 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:40:44 -0300
commit7ca4524a4cedfeddd6ffa4bcf4eb7465076d2d7d (patch)
tree110cb1ae497477bee9c52367eeaa23a90c050001 /src/host_io.zig
parentbfa624697612693a4a9e8596f5f96ffc8f84bf87 (diff)
downloadpardes-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/host_io.zig')
-rw-r--r--src/host_io.zig43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/host_io.zig b/src/host_io.zig
index 6ee38b6b..df016fd0 100644
--- a/src/host_io.zig
+++ b/src/host_io.zig
@@ -2689,17 +2689,39 @@ const darwin = struct {
/// reaped, killed if it is still there 100 ms on. A thread does the waiting
/// so that no host loop needs a timer for it (macOS's has none); a thread
/// that cannot start kills and reaps it here.
-/// ponytail: a shell still inside its 100 ms when the editor exits is left
-/// to init; the gui and detached hosts keep their own retired lists, which
-/// this could replace.
+/// ponytail: only the window waits for them at exit (waitRetired); the tui
+/// and macOS leave a shell still inside its 100 ms to init, a waitRetired at
+/// their exit if that matters.
pub fn retireShell(pid: libc.pid_t) void {
if (pid <= 0) return;
_ = libc.kill(pid, libc.SIG.HUP);
if (libc.waitpid(pid, null, libc.W.NOHANG) != 0) return;
- const thread = std.Thread.spawn(.{}, reapShell, .{ pid, 100 }) catch return reapShell(pid, 0);
+ _ = retiring.fetchAdd(1, .monotonic);
+ const thread = std.Thread.spawn(.{}, reapRetiring, .{pid}) catch {
+ _ = retiring.fetchSub(1, .monotonic);
+ return reapShell(pid, 0);
+ };
thread.detach();
}
+/// retireShell's threads still waiting on a shell.
+var retiring: std.atomic.Value(u32) = .init(0);
+
+fn reapRetiring(pid: libc.pid_t) void {
+ defer _ = retiring.fetchSub(1, .release);
+ reapShell(pid, 100);
+}
+
+/// An exit's sweep: every shell retireShell still waits on is seen out, gone
+/// on its hangup or killed at the end of its 100 ms, and reaped, rather than
+/// left to init.
+pub fn waitRetired() void {
+ while (retiring.load(.acquire) != 0) {
+ const ts: libc.timespec = .{ .sec = 0, .nsec = std.time.ns_per_ms };
+ _ = libc.nanosleep(&ts, null);
+ }
+}
+
// ---- a command pane's child, watched to its exit ----
//
// A command pane's command is done when its process exits, not when its pty
@@ -3545,16 +3567,3 @@ pub fn dumpThemes(core: *pardes.Pardes, io: std.Io, gpa: std.mem.Allocator, pane
var mbuf: [256]u8 = undefined;
core.setMessage(pane, pardes.Messages.Message.stamp(&mbuf, "dumped themes", out_dir));
}
-
-/// A retired shell reaped once it has exited, killed once its grace is up.
-pub fn reapRetired(pid: *std.c.pid_t, kill_at: *i64, now: i64) void {
- if (pid.* <= 0) return;
- const result = std.c.waitpid(pid.*, null, std.c.W.NOHANG);
- if (result > 0 or (result < 0 and std.c.errno(result) == .CHILD)) {
- pid.* = 0;
- kill_at.* = 0;
- } else if (kill_at.* != 0 and now >= kill_at.*) {
- _ = std.c.kill(pid.*, std.c.SIG.KILL);
- kill_at.* = 0;
- }
-}