diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 14:33:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 14:52:49 -0300 |
| commit | 1f731da28bd9983cc414839bd32372d183438164 (patch) | |
| tree | bfcc603bfe156ee5c317f72535ba6564b1d217f5 /runtime/upgrade.zig | |
| parent | 8a8ce0a6740e9a98ea37a70d401c3ba3fffe0ee1 (diff) | |
| download | pardes-1f731da28bd9983cc414839bd32372d183438164.tar.gz pardes-1f731da28bd9983cc414839bd32372d183438164.zip | |
pair: `kept`, whole (P36): a session's state the daemon hears is one of attached, detached, pair, kept (daemon.State, its hello's and `state` word, numbered as the daemon's record said its bool), a `new --detach` (and the bare `--detach`) under PARDES_PAIR kept from birth, a pair's session `pair` until a Detach typed in any client makes it kept (daemon.keepSession, never cleared), an Upgrade carrying it (the record's `state` word), and Peers.kept deleted: a client's close ends the session only while it is `pair` (Peers.leave), the end condition no longer asks Options.pair but for the daemonless pair; `pardes ps` says `(tty)` of a pair's session not kept and `(tty, kept)` of a kept one, an own-path session's line unchanged (`(tty, has a frontend)`, `(tty, detached)`), and a bare attach takes any session without a frontend; test/daemon.py `pair_rows` rewritten (a `new --detach` kept, its clients ended by HUP and TERM: runs on; a pair `(tty)` across an Upgrade, its Detach `(tty, kept)` across another, its clients ended by TERM, KILL, HUP: runs on), `pair` and `gui_pair` read the new line, and gui_pair closes a window client of a `new --detach` session: it runs on; on the base `--pair` fails at "the client listed" (ps said `(tty, detached)`), here it passes (load 5-8), shell-test's record and bare-attach tests 32/32 and 9/9
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'runtime/upgrade.zig')
| -rw-r--r-- | runtime/upgrade.zig | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index 37d4890b..f59117ee 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -19,6 +19,7 @@ const builtin = @import("builtin"); const libc = std.c; const posix = std.posix; const pardes = @import("core"); +const daemon = @import("daemon.zig"); pub const supported = builtin.os.tag == .linux or builtin.os.tag == .freebsd; pub const flag = "--upgraded="; @@ -140,6 +141,9 @@ pub const Record = struct { /// This process's own: its dump would not load, so it started afresh /// and adopts the shells. fresh: bool = false, + /// A pair's session's state (daemon.State): whether it is kept, which + /// the dump does not say. None: as its frontend says (attached or not). + state: ?daemon.State = null, pub fn addPty(rec: *Record, pane: usize, pid: libc.pid_t, fd: c_int) void { if (rec.nptys == rec.ptys.len or fd < 0) return; @@ -177,6 +181,7 @@ pub const Record = struct { for (rec.ttys[0..rec.nttys]) |t| try w.print("tty {d} {d} {d} {d} {x}\n", .{ t.view, t.fd, t.stub, @intFromBool(t.primary), std.mem.asBytes(&t.termios) }); if (rec.refused.len > 0) try w.print("refused {s}\n", .{rec.refused}); if (rec.label.len > 0) try w.print("label {s}\n", .{rec.label}); + if (rec.state) |s| try w.print("state {t}\n", .{s}); try w.print("exe {s}\ndump {s}\n", .{ rec.exe, rec.dump }); } @@ -191,7 +196,7 @@ pub const Record = struct { const rest = line[sp + 1 ..]; var it = std.mem.tokenizeScalar(u8, rest, ' '); // A word of a later build's record is passed over. - switch (std.meta.stringToEnum(enum { link, stub, old, window, pty, tty, refused, label, exe, dump }, word) orelse continue) { + switch (std.meta.stringToEnum(enum { link, stub, old, window, pty, tty, refused, label, state, exe, dump }, word) orelse continue) { .link => rec.link = try std.fmt.parseInt(c_int, rest, 10), .stub => rec.stub = try std.fmt.parseInt(c_int, rest, 10), .old => rec.old = try std.fmt.parseInt(c_int, rest, 10), @@ -225,6 +230,7 @@ pub const Record = struct { }, .refused => rec.refused = rest, .label => rec.label = rest, + .state => rec.state = std.meta.stringToEnum(daemon.State, rest), .exe => rec.exe = rest, .dump => rec.dump = rest, } @@ -383,9 +389,14 @@ pub fn dumpInto(core: *pardes.Pardes, rec: *Record, at: *[1024:0]u8, why: []u8) /// dump stays, a dump among the state file's): why, in words (`why`'s). pub fn execAs(gpa: std.mem.Allocator, path: [:0]const u8, rec: *const Record, at: [*:0]const u8, fs: ?*@import("9p_io.zig").Listener, why: []u8) []const u8 { _ = at; - @import("daemon.zig").upgraded(); + daemon.upgraded(); if (fs) |f| f.flushOut(); - const err_words = exec(gpa, path, -1, rec); + var with = rec.*; + with.state = switch (daemon.sessionState()) { + .pair, .kept => |s| s, + .attached, .detached => null, + }; + const err_words = exec(gpa, path, -1, &with); // Still here: the exec failed. if (rec.old >= 0) _ = libc.close(rec.old); return std.fmt.bufPrint(why, "Upgrade: {s} would not start: {s}; this session stays as it is", .{ path[0..@min(path.len, 600)], err_words }) catch "Upgrade: the new pardes would not start"; @@ -453,7 +464,7 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op } test "an upgrade's record reads back as it was written, and refuses one cut short" { - var rec: Record = .{ .link = 5, .stub = 7, .old = 9, .window = true, .exe = "/a b/pardes", .dump = "/home/u/.local/share/pardes/pardes.xitdb", .label = "upgrade-1" }; + var rec: Record = .{ .link = 5, .stub = 7, .old = 9, .window = true, .exe = "/a b/pardes", .dump = "/home/u/.local/share/pardes/pardes.xitdb", .label = "upgrade-1", .state = .kept }; rec.addPty(3, 1234, 11); rec.addPty(0, 99, 12); var tio: posix.termios = std.mem.zeroes(posix.termios); @@ -474,10 +485,12 @@ test "an upgrade's record reads back as it was written, and refuses one cut shor try std.testing.expectEqualStrings("/a b/pardes", back.exe); try std.testing.expectEqualStrings("/home/u/.local/share/pardes/pardes.xitdb", back.dump); try std.testing.expectEqualStrings("upgrade-1", back.label); - // An older build's: its dump a file, no label. + try std.testing.expectEqual(daemon.State.kept, back.state.?); + // An older build's: its dump a file, no label, no state. const older = try Record.decode("link 5\nexe /a\ndump /run/u/pardes-upgrade-1.dump\n"); try std.testing.expectEqualStrings("/run/u/pardes-upgrade-1.dump", older.dump); try std.testing.expectEqualStrings("", older.label); + try std.testing.expect(older.state == null); try std.testing.expectError(error.BadRecord, Record.decode("link 5\n")); try std.testing.expectError(error.BadRecord, Record.decode("tty 0 1 2 1 abc\ndump x\n")); } |
