summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 21:19:36 -0300
committerGabriel Schneider <[email protected]>2026-11-21 22:26:19 -0300
commit752cd81c1c5e1e91e1429cefc1c4651647981f88 (patch)
tree5c6ff207797f13deedbdc2d42b5ad1b2dd45a1f5 /core/replica.zig
parent27874074025f88dd9e27ece82c352c4a7c35ab51 (diff)
downloadpardes-752cd81c1c5e1e91e1429cefc1c4651647981f88.tar.gz
pardes-752cd81c1c5e1e91e1429cefc1c4651647981f88.zip
pair: a pair's session puts the user's terminal back when its client dies with no word (P48): a tty pair (runtime/main.zig `pair`) keeps /dev/tty and its termios as they are before the client enters it and hands them to the session (dev/tui/tui.zig `Term.pair`, `Kept`); `Peers` marks the pair's first peer (`Peer.pair`, from `Joining.own`) and a bye (`Peer.bye`) and says at that peer's leave whether it left with no word at all (`Peers.pair_left`: no bye, not let go by the session, not cut); the session's frontend (`Own.sent`, now before a no-daemon pair's end in runtime/session.zig) writes on a loss what the own path writes when a terminal is lost under it (`Killed`'s bytes, which now also turn the in-band resize off: vaxis's terminal query turns it on) and the cooked termios, and lets the device go either way (a terminal held open keeps an ssh or its emulator waiting); not across an Upgrade (close-on-exec) nor after the pair's client joined again; daemon.py plain with the variable passes on Debug (it failed at 'the terminal is put back'), its row after a killed stub listing `(tty)` under the variable (a loss: still a pair's, P36), and --upgrade counts the device let go at the exec; core-test 896/1056, shell-test 1098/1101
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig14
1 files changed, 13 insertions, 1 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 44fa922f..49dc7f7b 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -1717,6 +1717,12 @@ pub const Peer = struct {
again: bool = false,
/// ...or that its window was closed (Peers.closed).
close: bool = false,
+ /// It said a bye: none, and the session let it go with no word of its
+ /// own (`closing`, `cut`), is a client that died (killed: P48).
+ bye: bool = false,
+ /// A pair's first client (`Joining.own`): the terminal its session
+ /// keeps is its (`Peers.pair_left`).
+ pair: bool = false,
/// Its number in the session's `Screens`.
sid: u16 = 0,
/// Inputs read (each one's seq, as the client numbered them).
@@ -1998,6 +2004,7 @@ pub const Peer = struct {
const b = (wire.decodeClient(tag, payload) catch return false).bye;
peer.again = b.again;
peer.close = b.close;
+ peer.bye = true;
return false;
},
.ping => {
@@ -2130,6 +2137,10 @@ pub const Peers = struct {
/// hung up) and the session is a pair's not kept (daemon.sessionState): it
/// ends there (runtime/session.zig).
closed: bool = false,
+ /// Its pair's first client left (P48): with no word at all (killed),
+ /// true; its session's frontend puts the user's terminal back then,
+ /// and lets it go either way (tui.zig `Own.sent`), and clears this.
+ pair_left: ?bool = null,
/// An Upgrade told its clients so (`refuseAll`): a connection handed
/// over before its exec is told the same, never closed by the exec
/// unanswered. Its exec failed: the next boundary takes joins again.
@@ -2403,7 +2414,7 @@ pub const Peers = struct {
core.gpa.free(bytes);
return daemon.refuseReplica(fd, "out of memory");
};
- peer.* = .{ .peers = ps, .fd = fd, .id = ps.next_id, .view = .at(k), .dump = bytes, .blobs = blobs, .dump_gpa = core.gpa };
+ peer.* = .{ .peers = ps, .fd = fd, .id = ps.next_id, .view = .at(k), .dump = bytes, .blobs = blobs, .dump_gpa = core.gpa, .pair = joining.own };
ps.next_id +%= 1;
if (ps.next_id == 0) ps.next_id = 1;
// The session's digest as dumped, for the joiner to check its load by
@@ -2484,6 +2495,7 @@ pub const Peers = struct {
ps.closeViewOf(core, peer, peer.again or peer.cut);
if (ps.count() == 0) core.unattended = ps.detached;
if (ps.count() == 0 and peer.close and daemon.sessionState() == .pair) ps.closed = true;
+ if (peer.pair) ps.pair_left = !peer.bye and !peer.closing and !peer.cut;
ps.seq += 1;
ps.unit(0, ps.seq);
ps.letGo(peer);