summaryrefslogtreecommitdiff
path: root/dev/tui/tui.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 14:52:50 -0300
committerGabriel Schneider <[email protected]>2026-11-20 17:38:54 -0300
commitaa05797120cef3cd883ce053d56ba00fe866c009 (patch)
tree59db38cd8c02fc162bbc92f1411e7853512765a0 /dev/tui/tui.zig
parent1f731da28bd9983cc414839bd32372d183438164 (diff)
downloadpardes-aa05797120cef3cd883ce053d56ba00fe866c009.tar.gz
pardes-aa05797120cef3cd883ce053d56ba00fe866c009.zip
pair: a hang-up is a close (P36): a terminal client (`runClient`) blocks HUP and TERM before its join makes a thread and winchWatch takes both as `quit`, which in a client now sets the goodbye's close (as a window's close button does, and as SDL already makes a window client's TERM), so its terminal closed, its ssh dropped under it or a TERM says goodbye with the close, puts the terminal back and exits 0, and the session, a pair's not kept (daemon.State `pair`), ends when that was its last client; with other clients or kept it runs on, and a client killed outright stays a loss (no goodbye: it runs on, listed); without PARDES_PAIR the close is read by no session, so the own path's terminal closed still detaches its session, the one change a user sees there being a `pardes attach` client's TERM: a goodbye and exit 0 where it died of the signal; and a client exec'd at an Upgrade (runtime/client.zig `execAgain`) clears its signal mask first, since the mask crosses an exec and a build that sigwaits no TERM would never take one (found by `--upgrade` new->old with clients: the exec'd terminal client ignored the test's TERM for 20 s; with the clear both ways pass); test/daemon.py `pair_rows` gains 2.2 B's not-kept column (a client's terminal closed, not the last: runs on; the pair's own client killed -9: runs on, listed `(tty)`; the last client TERMed: exit 0, its terminal put back, the session ended; a pair upgraded, its terminal closed: ended) and the own path's rows (an attach client TERMed: the session on; its terminal closed: `(tty, detached)`); on the change before, `--pair` fails at the TERMed client's status (-15); here: tui core-test 861/1016 (155 skipped), shell-test 1058/1061, term 17/17, pane 183/184, kitty 45/45, behaviour-test and --replay 275/275, process-test 0 of 144 failed, soak --clients 5 diverged 0, unequal 0, checked/wrong 1874/0 1937/0, quiet checks 597/0 673/0 779/0, unlisted 0, corpus 22 of 22, no leak, --bytes --clients 5 the same (quiet checks 693/0 586/0 802/0), daemon.py plain (launch, pair, pair_rows), --far, --relink, --manage, --window-clients, --gui (gui_pair) pass, an idle terminal pair wakes 0 and 0 times in 2 s, gui unit-test 1654/1658 with only BaselineHarnessMismatch, --games, --upgrade with clients both ways against the base built with -Dembed-sources=true (another semantics) pass, nothing left behind by any mode (load 4-18)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev/tui/tui.zig')
-rw-r--r--dev/tui/tui.zig23
1 files changed, 15 insertions, 8 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index 72028b04..67c0e2a0 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -721,19 +721,22 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8,
std.process.exit(1);
}
};
- var start: client_loop.Start = undefined;
- if (!start.open(init, opts, .{ .path = path, .session = session, .far = far_link })) Said.no(io, "{s}", .{start.said()});
- defer start.close();
-
+ // Blocked before its join makes a thread, so that winchWatch alone
+ // takes them: a hangup (its terminal closed) or a TERM ends it the
+ // normal way (`quit`), its goodbye a close (a pair's session not kept
+ // ends at its last client's), what it made kept on disk (`Have.keep`)
+ // and its ssh forward's socket unlinked (main.zig).
var winch_set = posix.sigemptyset();
posix.sigaddset(&winch_set, posix.SIG.WINCH);
- // A hangup ends it the normal way (`quit`), what it made kept on disk
- // (`Have.keep`) and its ssh forward's socket unlinked (main.zig).
posix.sigaddset(&winch_set, posix.SIG.HUP);
+ posix.sigaddset(&winch_set, posix.SIG.TERM);
hangup_quits = true;
if (comptime builtin.os.tag == .freebsd)
posix.sigaction(.WINCH, &.{ .handler = .{ .handler = keepSignal }, .mask = posix.sigemptyset(), .flags = 0 }, null);
posix.sigprocmask(posix.SIG.BLOCK, &winch_set, null);
+ var start: client_loop.Start = undefined;
+ if (!start.open(init, opts, .{ .path = path, .session = session, .far = far_link })) Said.no(io, "{s}", .{start.said()});
+ defer start.close();
var tty_buf: [0x10000]u8 = undefined;
var screen: Screen = .{ .io = io, .gpa = gpa, .env = init.environ_map, .buf = &tty_buf, .kitty = .init(gpa) };
defer screen.kitty.deinit();
@@ -1544,7 +1547,10 @@ const Shell = struct {
virtual.* = @max(virtual.*, s.wake_to);
},
.quit => {
+ // A client's terminal went (a hangup, its input's end) or it
+ // took a TERM: a close, as a window's close button.
if (s.client) |c| {
+ c.link.close = true;
c.link.quit = true;
return true;
}
@@ -1939,19 +1945,20 @@ const Shell = struct {
fn keepSignal(_: posix.SIG) callconv(.c) void {}
-/// A replica client's (`runClient`): a hangup is its end, whoever sent it.
+/// A replica client's (`runClient`): a hangup or a TERM is its end.
var hangup_quits = false;
fn winchWatch(loop: *Loop) void {
var set = posix.sigemptyset();
posix.sigaddset(&set, posix.SIG.WINCH);
if (daemon.link >= 0 or hangup_quits) posix.sigaddset(&set, posix.SIG.HUP);
+ if (hangup_quits) posix.sigaddset(&set, posix.SIG.TERM);
while (true) {
var sig: c_int = 0;
if (libc.sigwait(&set, &sig) != 0) continue;
// The terminals are the loop's: it asks each its size, and takes a
// hangup as the end of the one that hung up.
- const ev: Msg = if (sig != @backingInt(posix.SIG.HUP)) .winched else if (hangup_quits) .quit else .hangup;
+ const ev: Msg = if (sig == @backingInt(posix.SIG.WINCH)) .winched else if (hangup_quits) .quit else .hangup;
loop.postEvent(ev) catch {};
}
}