diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-29 10:48:56 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-29 12:01:27 -0300 |
| commit | 4ffe5c93b3087f245f5b57a822ab0ecf41cc085c (patch) | |
| tree | ede4d5de12fe169838f1f5993a9896bd32f45715 /src/pardes.zig | |
| parent | cb2a6cd79e443d671f5255d262ea79b7e26552a5 (diff) | |
| download | pardes-4ffe5c93b3087f245f5b57a822ab0ecf41cc085c.tar.gz pardes-4ffe5c93b3087f245f5b57a822ab0ecf41cc085c.zip | |
sessions register with the daemon: a terminal's session forked off its stub, Detach and --attach in place for terminals and windows, pty masters kept, Adopt
pardes in a terminal reaches (or starts) the daemon, opens /dev/tty and forks: the child is the session, in a session of its own (setsid), drawing on that terminal (tty.Term.fd, a raw vaxis Tty made from the fd); the parent stays as its stub, the job the shell waits on. Not the daemon spawning it from a passed fd, env and argv: the user's terminals each run in a 9ns user and mount namespace, which a session spawned by a per-user daemon would not share, and a fork costs one small process's page tables where the spawn cost an IPC and an exec. GUI windows and --detach sessions just register.
tty: Detach (and a terminal's end: EOF, EIO, a hangup the stub passes on, taken on the signal thread) puts the terminal back, drops it and the stub's stdio, tells the stub (which ends, exit 0), and leaves the session running with nothing drawn (Host.watched), its messages on the clock and `size` its own. pardes --attach[=name] hands its terminal through the daemon; the session enters it as the first one, sized, queried and drawn whole, and that process is its stub until it leaves. A hangup never ends a kept session; TERM and INT do, telling the daemon so the shells go with it (one async-signal-safe send).
gui: Detach closes the window (its swapchain or renderer) and keeps the device, atlas and pipelines; the loop sleeps on SDL's queue; pardes-gui --attach[=name] opens a window again. Closing a window still quits.
--detach is a session started detached: the tty host with no terminal yet, the GUI with a hidden window closed at once. forkShell sends the daemon a dup of every master and the hosts tell it what they close, so a session killed outright leaves its shells running; the new Adopt word takes them in as terminal panes (the Tty word's pane, its spawn taking the pty, a 1x1 size then the pane's to make it redraw).
The Attach word, which switched a session's own terminal to a detached session through the frames, goes, with its effect and request in the core. PARDES_DAEMON=off (the e2e harness's) runs a session as before. test/daemon.py: 50 detach/attach cycles at a level fd count with no stale socket, kill -9 and Adopt, and nothing left; --gui the same for a window. test/fs.py: a forked session's socket is found by its own pid, and a hangup leaves a kept session running.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/pardes.zig')
| -rw-r--r-- | src/pardes.zig | 72 |
1 files changed, 2 insertions, 70 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index c7ae6704..2bee1f98 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -538,53 +538,8 @@ fn drainForSavePath(p: *Pardes, buf: []u8) ?[]const u8 { return if (len) |n| buf[0..n] else null; } -fn drainForAttach(p: *Pardes) ?AttachRequest { - while (p.nextEffect()) |effect| p.perform(effect); - return p.takeAttach(); -} - -test "Attach asks for a session and tears nothing down" { - if (comptime !can_attach) return; - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - - // Bare means whichever session is there, and that is an EMPTY name rather - // than an absent request: the frontend still has to go and look. - try std.testing.expect(p.executeBuiltinLine(0, "Attach")); - const bare = drainForAttach(p) orelse return error.NoAttachAsked; - try std.testing.expectEqualStrings("", bare.name); - try std.testing.expectEqual(@as(u8, 0), bare.pane); - - // ...and the named form carries its tail, the way `Theme <name>` does. - try std.testing.expect(p.executeBuiltinLine(0, "Attach work")); - const named = drainForAttach(p) orelse return error.NoAttachAsked; - try std.testing.expectEqualStrings("work", named.name); - try std.testing.expect(p.takeAttach() == null); // taken once, then gone - - // The word only ASKS. A core that tore itself down here could not be handed - // back intact when the connect fails, and that is the entire guarantee. - try std.testing.expect(!p.quit); - try std.testing.expect(p.panes[0] != null); -} - -test "Attach in a detached session: bare is wrong #args, a name no session has says so, and nothing is asked" { - if (comptime !can_attach) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .detached_session = true }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - const pane = p.panes[0].?; - try std.testing.expect(p.executeBuiltinLine(0, "Attach")); - try std.testing.expect(drainForAttach(p) == null); - try std.testing.expectStringStartsWith(pane.msg[0..pane.msg_len], "wrong #args"); - try std.testing.expect(p.executeBuiltinLine(0, "Attach zz-no-such-session-qq")); - try std.testing.expect(drainForAttach(p) == null); - try std.testing.expectEqualStrings("Attach: zz-no-such-session-qq: no such session", pane.msg[0..pane.msg_len]); -} - -test "Detach asks the frontend to leave, and says so when there is nothing to leave" { - if (comptime !can_attach) return; // compiled out where nothing polls `takeAttach` — see `can_attach` +test "Detach asks the host to let its terminal go, and says so when there is nothing to leave" { + if (comptime !can_attach) return; // the word is compiled out elsewhere: see `can_attach` const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true }); defer p.deinit(); @@ -3753,10 +3708,6 @@ pub const Event = union(enum) { tick, }; -pub const attach_name_max = 256; - -pub const AttachRequest = struct { pane: u8, name: []const u8 }; - pub const PendingWrite = struct { bytes: []u8, off: usize = 0 }; /// `command` is Kill's: SIGTERM to the terminal's foreground job, and never @@ -3807,7 +3758,6 @@ pub const Effect = union(enum) { /// Write the build-time theme ring below the per-user config directory. /// The pane receives the completion/error message from the native host. dump_themes: struct { pane: u8 }, - attach: struct { pane: u8, name: Buf(attach_name_max) }, detach: struct { pane: u8 }, quit, @@ -4387,9 +4337,6 @@ pub const Options = struct { /// window opens one as big as that, Handover.zig). geometry: ?[]const u8 = null, nested: bool = false, - /// The core of a `--detach` session (detached/server.zig): it has no - /// terminal of its own, so Attach there is refused with why. - detached_session: bool = false, startup_config: ?[]const u8 = null, ninep_name: []const u8 = "", ninep_tcp: ?[]const u8 = null, @@ -4738,8 +4685,6 @@ pub const Pardes = struct { /// shell consumes it via takeRestore each frame (restore contents stay host-fed) restore_req: ?[]const u8 = null, restore_buf: [1024]u8 = undefined, - attach_req: ?AttachRequest = null, - attach_buf: [attach_name_max]u8 = undefined, surface: Surface = .{}, /// per-update scratch (paneCursorLines, selection text); reset each update @@ -5088,14 +5033,6 @@ pub const Pardes = struct { return r; } - /// the shell polls this each frame beside takeRestore: a pending Attach's - /// session and reporting pane, or null - pub fn takeAttach(p: *Pardes) ?AttachRequest { - const a = p.attach_req; - p.attach_req = null; - return a; - } - /// The workspace tag's height: one row while the setting keeps it, as /// acme's row tag is, zero once a native shell takes its commands over. /// Layout and hit testing read this rather than the constant, the way @@ -5981,11 +5918,6 @@ pub const Pardes = struct { }, .theme_file => |t| if (v.watch_theme) |f| f(p.host.ctx, t.generation, t.on), .dump_themes => |d| if (v.dump_themes) |f| f(p.host.ctx, d.pane), - .attach => |a| { - const name = a.name.slice(); - @memcpy(p.attach_buf[0..name.len], name); - p.attach_req = .{ .pane = a.pane, .name = p.attach_buf[0..name.len] }; - }, .detach => |d| if (v.detach) |f| f(p.host.ctx) else |
