summaryrefslogtreecommitdiff
path: root/runtime/upgrade.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 18:08:49 -0300
committerGabriel Schneider <[email protected]>2026-11-20 18:08:49 -0300
commit4053e62a2aabd794db9075d93ebe57eec3f432a6 (patch)
treeb5a676e835b4df79f0670056a636410c97ffb8fd /runtime/upgrade.zig
parente3d0daa9f89f41b41b7d05d510db553cbd8816d9 (diff)
parent6683e03a40c0bbd88dadf6bb30121d41e944207c (diff)
downloadpardes-4053e62a2aabd794db9075d93ebe57eec3f432a6.tar.gz
pardes-4053e62a2aabd794db9075d93ebe57eec3f432a6.zip
integration: a hang-up is a close and a session can be kept, on the 9P state a join carries: pardes-pair-3 (a session's state as the daemon hears it: attached, detached, pair or kept, carried through an Upgrade; a terminal client takes HUP and TERM itself and leaves with a goodbye that closes; ps shows (tty) for a pair and (tty, kept); the documents say what PARDES_PAIR is) and pardes-merge40, merged without a textual conflict; tui core-test 871/1028 (157 skipped), shell-test 1070/1073, term-test 17/17, both soaks diverged 0, unequal 0, unlisted 0, the window builds; the coordinator's gate in the ledger (reorg/merge41)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'runtime/upgrade.zig')
-rw-r--r--runtime/upgrade.zig23
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"));
}