summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep')
-rw-r--r--src/ninep/pty.zig15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig
index d32c35fd..41748bdc 100644
--- a/src/ninep/pty.zig
+++ b/src/ninep/pty.zig
@@ -61,6 +61,10 @@ pub fn writeCtl(p: *Pardes, req: Req, id: usize) Reply {
while (it.next()) |raw| {
const line = std.mem.trim(u8, raw, " \t\r");
if (line.len == 0) continue;
+ // A command pane's child is its command, done or running: exec
+ // would run its line again with no header, footer or records.
+ if (!apply and std.mem.eql(u8, line, "exec")) if (p.panes[id]) |pane| if (pane.command != null)
+ return tree.failText(req.tag, E.INVAL, "invalid exec: a command pane does not restart");
// A shell restarted where the directory is gone would not start:
// refused before anything runs, as Tty there is.
if (!apply and std.mem.eql(u8, line, "exec")) if (p.panes[id]) |pane| if (pardes.exec.missingDir(p, pane.cwdSlice())) {
@@ -1087,3 +1091,14 @@ test "a run's answer longer than its room is cut, its newline kept" {
try testing.expectEqual(slot.answer.len, slot.len);
try testing.expectEqual(@as(u8, '\n'), slot.answer[slot.len - 1]);
}
+
+test "exec on a command pane is refused: a command pane does not restart" {
+ const p = try th.withTerm(testing.allocator);
+ defer p.deinit();
+ const serial = th.serialOf(p);
+ const pane = p.panes[p.paneBySerial(serial).?].?;
+ pane.command = try p.gpa.dupe(u8, "echo hi");
+ const r = th.wr(p, tree.Node.of(serial, .pty_ctl), "exec\n");
+ try testing.expectEqual(tree.E.INVAL, r.errno());
+ try testing.expectEqualStrings("invalid exec: a command pane does not restart", r.reply.ename);
+}