diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-22 19:59:00 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-22 20:09:15 -0300 |
| commit | 34e2d82a322bd3767a8ec62b3a4c0894399e8c04 (patch) | |
| tree | f017d7aa398d51daf132367c3587d824907e6759 | |
| parent | 79b73e14711e48e61d0f742622671a8fcfd8d054 (diff) | |
| download | pardes-34e2d82a322bd3767a8ec62b3a4c0894399e8c04.tar.gz pardes-34e2d82a322bd3767a8ec62b3a4c0894399e8c04.zip | |
tty: a TERM that reaches a session while it leaves its terminal (a quit, a Detach, the detach a hangup makes) no longer leaves that terminal raw for good: `Screen.leave` let `Killed` go first and the cooked modes came back last (vaxis's `Tty.deinit`), after the kitty images, the alternate screen's exit (flushed at once) and vaxis's teardown, so a TERM in between found nothing to put back and died with the main screen back and the modes raw, nothing of pardes putting them back after it (at a quit the stub then dies of the same TERM, and a shell that does not reset its own modes prompts on a raw terminal); now `Killed.disarm` puts the cooked modes back itself and is called last, just before vaxis's own put-back, so a TERM anywhere in a leave finds them back or puts them back (dev/tui/tui.zig); the process case `killedTty` failed so in about one gate in ten (merge49 and merge58, "the terminal left raw" with the main screen back: its HUP round, which TERMs the session right after the stub dies of the hangup, while the session leaves the terminal that hung up) and now names its signal; not reproduced as it is (the base pinned to one CPU 0 of 40 failed, unpinned beside a second copy 0 of 80); with the window widened by an experiment's 300 ms sleep before vaxis's put-back and the test's TERM 100 ms after the stub's death, the base failed 10 of 10 with the gates' words ("HUP: the terminal left raw", the main screen back, 3.7-4.5 s as the gates' 3.6 and 4.2 s) and this passed 10 of 10 with the same sleep after its disarm; after: the case pinned 40 of 40, core-test 917/1074 (157 skipped), shell-test 1116/1119 (3 skipped), process-test 0 of 146 (load 10.6), as pairs 0 of 146 (load 11.7, `tty boot: ninep` refused a dial in the parallel batch and passed again alone); left as it is: on a hangup the stub dies at once (runtime/daemon.zig `forward`), before the session has left the terminal, so with the terminal still there (a `kill -HUP` of the job) the shell's prompt comes before the session's put-back, which then sets the cooked modes and the main screen over it (not raw)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
| -rw-r--r-- | dev/tui/tui.zig | 16 | ||||
| -rw-r--r-- | test/process/flags.zig | 2 |
2 files changed, 12 insertions, 6 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 9117d54d..5d75722f 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -901,12 +901,14 @@ const Screen = struct { fn leave(sc: *Screen) void { if (!sc.on) return; sc.on = false; - Killed.disarm(); clearNativeImages(&sc.kitty, &sc.vx, &sc.tty); sc.vx.exitAltScreen(sc.tty.writer()) catch {}; sc.vx.deinit(sc.gpa, sc.tty.writer()); if (comptime !builtin.is_test) vaxis.tty.global_tty = null; - sc.tty.deinit(); // restore cooked termios LAST, after vx flushed its resets + // The cooked modes back LAST, after vx flushed its resets, and Killed + // armed until they are. + Killed.disarm(); + sc.tty.deinit(); } /// Its terminal hung up, or the stub that waits on it is gone. @@ -950,10 +952,14 @@ const Killed = struct { _ = std.c.tcsetattr(tty, .FLUSH, termios); } - /// The terminal gone (put back, or detached): a TERM still takes the - /// socket, the prompt files and the shells with it, and leaves the - /// terminal alone. + /// The terminal let go (Screen.leave): its cooked modes put back first, + /// so that a TERM anywhere in a leave finds them back or puts them back + /// itself (let go first, a TERM before vaxis put them back died leaving + /// the terminal raw for good); then a TERM still takes the socket, + /// the prompt files and the shells with it, and leaves the terminal + /// alone. fn disarm() void { + if (fd >= 0) _ = std.c.tcsetattr(fd, .FLUSH, &cooked); fd = -1; } diff --git a/test/process/flags.zig b/test/process/flags.zig index cfdb1faf..3c54a7ad 100644 --- a/test/process/flags.zig +++ b/test/process/flags.zig @@ -746,7 +746,7 @@ fn killedTty(gpa: std.mem.Allocator, exe: [:0]const u8) !void { const seen = try d.get(a, std.fs.path.basename(log)); const tail = seen[std.mem.lastIndexOf(u8, seen, "\x1b[?1049h").?..]; try check(has(tail, "\x1b[?1049l"), "the main screen not put back", .{}); - try check(try process.canonical(killed.slave), "the terminal left raw", .{}); + try check(try process.canonical(killed.slave), "{t}: the terminal left raw", .{sig}); daemonGone(&d); } } |
