From 9ac223e5436a9f5831c97382270dedbf9f13277d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 04:00:33 -0300 Subject: --wait waits on the pane its look answered, read on the look's own open, not one found again by name in /index The forwarded look was a write and nothing more, and --wait then looked its file up in /index. /index shows names escaped (`\\` for a backslash, `\xNN`), so a file named with one matched no pane and --wait exited 0 at once, as if the pane were already closed. The look is now asked on one open (Client.ask) and its answer is the pane waited on; /index by name stays only for a look that answers none. Co-Authored-By: Claude Opus 5.5 --- src/main.zig | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main.zig b/src/main.zig index 6c46b22c..de501047 100644 --- a/src/main.zig +++ b/src/main.zig @@ -281,11 +281,12 @@ fn forwardWords(err: anyerror, buf: []u8) []const u8 { /// connection ends with the session -- exit 1. fn waitForDel(io: std.Io, gpa: std.mem.Allocator, dial: []const u8, path: []const u8, known: ?u32) noreturn { _ = io; - // The pane this launch made (a name not there yet) is known by its - // serial; one a look opened or went to is found by its file. Found by - // none after the look went there, it was closed already: that is the - // end being waited for, not a failure (a pane closed between the look - // and this read made `--wait` exit 1 before). + // The pane this launch made (a name not there yet), or the one its + // look answered, is known by its serial; one the look answered none + // for is found by its file. Found by none after the look went there, + // it was closed already: that is the end being waited for, not a + // failure (a pane closed between the look and this read made `--wait` + // exit 1 before). const serial = known orelse found: { const first = ninep_io.Client.read(gpa, dial, "/index", "/index") catch std.process.exit(1); defer gpa.free(first); @@ -660,7 +661,11 @@ fn nativeMain(init: std.process.Init) !void { if (found_path != null) { var command_buf: [8192]u8 = undefined; const command = std.fmt.bufPrint(&command_buf, "{s}{s}\n", .{ path, word[target.path.len..] }) catch |err| Refuse.with(init.io, word, err); - ninep_io.Client.write(arena, parent.dial, look, command) catch |err| Refuse.with(init.io, word, err); + // The pane it went to, read on the open that asked (another + // client's look meanwhile is not this one's): what --wait waits on. + const went = ninep_io.Client.ask(arena, parent.dial, look, command) catch |err| Refuse.with(init.io, word, err); + var rows = std.mem.tokenizeAny(u8, went, " \n"); + if (rows.next()) |row| made_serial = std.fmt.parseInt(u32, row, 10) catch null; } else { const made = ninep_io.Client.read(arena, parent.dial, "/pane/new", "/pane/new") catch |err| Refuse.with(init.io, word, err); const serial = std.fmt.parseInt(u32, std.mem.trim(u8, made, " \n"), 10) catch |err| Refuse.with(init.io, word, err); -- cgit v1.3