summaryrefslogtreecommitdiff
path: root/src/tty/tty.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/tty/tty.zig')
-rw-r--r--src/tty/tty.zig15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/tty/tty.zig b/src/tty/tty.zig
index 903c5c0c..b2768ed6 100644
--- a/src/tty/tty.zig
+++ b/src/tty/tty.zig
@@ -924,6 +924,7 @@ const Shell = struct {
.pty_write = ptyWrite,
.pty_resize = ptyResize,
.pty_signal = ptySignal,
+ .close_pty = closePty,
.tty_taken = ttyTaken,
.write_file = writeFile,
.write_dump = writeDump,
@@ -1227,6 +1228,20 @@ const Shell = struct {
if (s.ptys[pane]) |pt| host_io.signalTty(pt.pid, pt.file.handle, sig);
}
+ /// The pane is gone: hang its pty up, which the kernel passes on to the
+ /// shell as SIGHUP, and say it too for a shell that ignores the tty's.
+ /// Output still in flight carries the old generation and is dropped.
+ fn closePty(ctx: ?*anyopaque, pane: u8) void {
+ const s = of(ctx);
+ var pt = s.ptys[pane] orelse return;
+ s.ptys[pane] = null;
+ s.gens[pane] +%= 1;
+ pt.reader.cancel(s.io) catch {};
+ _ = libc.close(pt.file.handle);
+ _ = libc.kill(pt.pid, posix.SIG.HUP);
+ _ = libc.waitpid(pt.pid, null, posix.W.NOHANG);
+ }
+
fn ttyTaken(ctx: ?*anyopaque, pane: u8) bool {
const s = of(ctx);
const pt = s.ptys[pane] orelse return false;