summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep')
-rw-r--r--src/ninep/ctl.zig28
-rw-r--r--src/ninep/tree.zig3
2 files changed, 31 insertions, 0 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index bcf9ffd6..c88eb328 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -4028,3 +4028,31 @@ test "pager answers its +Pager on the open that asked, whatever another client e
// One directory a write.
try testing.expectEqual(E.INVAL, wr(p, pager, "/a\n/b\n").errno());
}
+
+test "a command pane an exec open was answered is leased to it while it stays open: another client's command gets a pane of its own" {
+ const p = try withFile(testing.allocator, "x\n");
+ defer p.deinit();
+ const exec = Node.of(serialOf(p), .exec);
+ const Client = struct {
+ fn run(pp: *Pardes, node: u64, h: u32, line: []const u8) !usize {
+ try testing.expectEqual(Status.ok, call(pp, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = line }).reply.status);
+ const id = pp.paneBySerial(pp.fs.results[0]).?;
+ // Its command finishes and its output ends.
+ pp.panes[id].?.command_done = true;
+ pp.panes[id].?.command_pty = false;
+ return id;
+ }
+ };
+ const a = call(p, .{ .tag = 1, .op = .open, .node = exec, .omode = 2 }).reply.handle;
+ const b = call(p, .{ .tag = 1, .op = .open, .node = exec, .omode = 2 }).reply.handle;
+ const a_pane = try Client.run(p, exec, a, "echo a\n");
+ const b_pane = try Client.run(p, exec, b, "echo b\n");
+ try testing.expect(a_pane != b_pane);
+ // Each one's next command runs in its own pane again.
+ try testing.expectEqual(a_pane, try Client.run(p, exec, a, "echo a2\n"));
+ try testing.expectEqual(b_pane, try Client.run(p, exec, b, "echo b2\n"));
+ // Closed, a lease ends: the directory's one command pane is reused.
+ _ = call(p, .{ .tag = 3, .op = .release, .node = exec, .handle = a, .opened = true });
+ try testing.expectEqual(Status.ok, wr(p, exec, "echo c\n").reply.status);
+ try testing.expectEqual(a_pane, p.paneBySerial(p.fs.results[0]).?);
+}
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index 9c3e1e9c..e5d1c848 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -1212,6 +1212,9 @@ fn write(p: *Pardes, req: Req, target: Target) Reply {
o.pending.shrinkRetainingCapacity(rest);
var w = req;
w.data = whole;
+ // The command pane this open was answered holds no lease against its
+ // own next command (exec.leased): that one may run there again.
+ if (resultsFile(target)) o.results.len = 0;
var reply = writeNow(p, w, target);
if (resultsFile(target)) {
@memcpy(o.results.list[0..p.fs.results_len], p.fs.results[0..p.fs.results_len]);