From 0f18cc317190c2aaaf0efec4cd6da656cb1f3402 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 28 Sep 2026 14:36:46 -0300 Subject: A spawn names the pane it was made for, so a pane closed and its slot retaken spawns nothing The spawn effect carried only a slot, and the host read the command and shell off whatever pane held the slot as it forked: a command pane closed and its slot taken by the next one before the effects ran forked the new pane's command twice. The effect now carries the pane's serial and is dropped when the slot holds another; forkShell checks it again after giving up the turn for its directory's stat, the one moment a 9P client can change the panes under it. Every front end performs spawns with the turn, from its step. Co-Authored-By: Claude Opus 5.5 --- src/host_io.zig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/host_io.zig') diff --git a/src/host_io.zig b/src/host_io.zig index 63b907ac..b167ef8a 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -965,6 +965,7 @@ pub fn forkShell( const native_cwd = filesystem.localPath(cwd) orelse cwd; if (std.mem.indexOfScalar(u8, native_cwd, 0) != null) return error.InvalidPath; var cwd_buf: [4096]u8 = undefined; + const serial = if (core) |c| if (c.panes[pane]) |pn| pn.serial else 0 else 0; const cwd_z: ?[:0]const u8 = if (native_cwd.len == 0) null else dir: { const path = std.fmt.bufPrintSentinel(&cwd_buf, "{s}", .{native_cwd}, 0) catch return error.NameTooLong; // A shell's directory may be inside a mount this editor serves. @@ -974,6 +975,9 @@ pub fn forkShell( if (stat.kind != .directory) return error.NotDir; break :dir path; }; + // The turn was given up for the stat: a 9P client may have closed the + // pane, and another taken its slot, whose command this is not. + if (core) |c| if ((if (c.panes[pane]) |pn| pn.serial else 0) != serial) return error.PaneGone; var master: c_int = -1; var path_buf: [std.fs.max_path_bytes]u8 = undefined; // A terminal opened on a shell of its own (`Tty fish`) runs that one. -- cgit v1.3