diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 03:20:04 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 04:13:33 -0300 |
| commit | 4c2125ecf47588d33f9894c1fdf2833d0512f3b4 (patch) | |
| tree | c76510fd390e20187554ea86a3fdabd2dfb65ca5 /src/replica.zig | |
| parent | d1d5d3cfb18841604bba2057eeb3598f729b4475 (diff) | |
| download | pardes-4c2125ecf47588d33f9894c1fdf2833d0512f3b4.tar.gz pardes-4c2125ecf47588d33f9894c1fdf2833d0512f3b4.zip | |
client #2, one frontend a session: the daemon answers `other <name>` for an attach to a session attached already (as it did for one of the other kind), so a second `pardes --attach` or `pardes-gui --attach` on this machine is a replica client through the replica socket, the path a remote one takes; a session tells the daemon its clients (SO_PEERCRED on each replica socket, at every join and leave) and `--ps` lists `client <pid> <command>` under it; the tty's per-terminal Screens (Screen.create/drop/destroy, primary, its stub and Killed slot), the Poster and its `from` input, the Gui's window-fields swap (window_fields, GuiWindow, copyWindow, freshWindow, follow, route, openAnotherWindow, closeView, windowsOpen, closeOtherWindows, resumeWindows), drawOthers and every harness's extra terminals (snapshot.zig's `start ... views=N` and `view <k>`, e2e_harness's initView and drainOthers, PARDES_TEST_VIEWS in both frontends, the GUI feed's `view;<k>`, the monkey's --views) go; the pump draws the one view this process shows (views.shown), through drawOne when a client's input was the last; an Upgrade from a build that kept a second terminal of its own lets it go (its stub told it is detached) and closes its view; deleted: views.snap, views-term.snap and views-pan.snap with their goldens (the in-process second terminal they drove is gone; views.zig's unit tests keep the per-view cursor, layout, register, sizing, closing and panning behaviour, test/replicas.zig and the soak the views of clients); the two views.zig tests that drew through drawOthers draw through drawOne; daemon.py's second terminal is a client listed by --ps, typed into in both terminals, detached from inside and closed; its second window a client listed by --ps and closed; the reference and next-daemon.md say so; no golden changes; gates: core-test 956/956 both, behaviour-test 248/248 both, unit-test 1487/1488 tui and 1530/1531 gui, pane-test 171/172 both, snap all 102 ok, process-test 0 of 37 failed on both, hxdiff 19 and hxparity 6 mismatches (the base's names), hxgolf 0, replicas, addon-test, gui-golden and monkey-gui 0 of 1 failed, daemon.py main, --window-clients and --gui ok, soak local pass (differ, mispred, view_bad, lost 0)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/replica.zig')
| -rw-r--r-- | src/replica.zig | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/replica.zig b/src/replica.zig index 40353d89..622537d7 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -1443,11 +1443,24 @@ pub const Framer = struct { } }; +/// The process at the other end of unix socket `fd` (Linux's SO_PEERCRED), +/// or 0: a client's through ssh is ssh's. +fn peerPid(fd: c_int) libc.pid_t { + if (comptime builtin.os.tag != .linux) return 0; + const Cred = extern struct { pid: libc.pid_t, uid: libc.uid_t, gid: libc.gid_t }; + var cred: Cred = undefined; + var len: libc.socklen_t = @sizeOf(Cred); + if (libc.getsockopt(fd, libc.SOL.SOCKET, libc.SO.PEERCRED, &cred, &len) != 0) return 0; + return cred.pid; +} + pub const Peer = struct { peers: *Peers, fd: c_int, id: u16, view: u8, + /// Its process (its socket's peer), for `--ps`; 0 not known. + pid: libc.pid_t = 0, /// Its bye said it joins again for its view (a divergence's rejoin): /// kept for it (views.away), not closed. Its reader's, read after its end. again: bool = false, @@ -2011,6 +2024,8 @@ pub const Peers = struct { return; } slot.* = peer; + peer.pid = peerPid(fd); + ps.tellClients(); // Its terminals afresh, after its dump and before any unit. if (ps.screens.addPeer()) |sid| { peer.sid = sid; @@ -2025,6 +2040,7 @@ pub const Peers = struct { slot.* = null; }; log.info("client {d} left '{s}'", .{ peer.id, ps.name }); + ps.tellClients(); ps.screens.dropPeer(peer.sid); core.undrawn &= ~(@as(u8, 1) << @intCast(peer.view)); ps.closeViewOf(core, peer, peer.again); @@ -2120,6 +2136,17 @@ pub const Peers = struct { peer.dump = &.{}; } + /// The daemon told the clients there are now (`pardes --ps`). + fn tellClients(ps: *const Peers) void { + var pids: [pardes.views.max]libc.pid_t = undefined; + var n: usize = 0; + for (ps.list) |slot| if (slot) |peer| { + pids[n] = peer.pid; + n += 1; + }; + daemon.clients(pids[0..n]); + } + /// Detach typed in client view `k`'s: its link ends (its reader says /// it is gone, and the next boundary lets it go). pub fn detach(ps: *Peers, k: u8) bool { @@ -2155,6 +2182,7 @@ pub const Peers = struct { ps.screens.dropPeer(peer.sid); ps.letGo(peer); }; + ps.tellClients(); ps.stop(core); ps.lock.lockUncancelable(ps.io); for (ps.inbox.items) |note| switch (note) { |
