diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-21 09:10:24 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-21 09:10:24 -0300 |
| commit | c4f7bb9477c7aa4c8864f14edb9e85b6c8c08437 (patch) | |
| tree | 9b60bce9e53f96855b40f2ba53e23945a7798ddf /test/process.zig | |
| parent | f7de6f49ee3d9ac241575f5244743193c9943841 (diff) | |
| parent | 5ad6067936f306271b875aaf182d4866055da10d (diff) | |
| download | pardes-c4f7bb9477c7aa4c8864f14edb9e85b6c8c08437.tar.gz pardes-c4f7bb9477c7aa4c8864f14edb9e85b6c8c08437.zip | |
integration: the pair's round 5 and the layers' round 2 on the gathered line: pardes-pair-5 (`ssrtxkzx`, on pardes-merge48: a link an Upgrade cuts with no last word asks the daemon whether its session is listed still and joins again (`replica.cutListed`): an upgrade from the installed build carries its clients; a no-daemon pair refuses Restore in words (P42); /dev/tty opened before the pair forks; a TERMed or hung-up client dies of the signal; the process suite as pairs 13 to 8 of 145) and pardes-layers-2 (`myxnnquu`, on pardes-merge49: the click on path@rev tested, a revision read-only from 9P, Syntax off in a patch keeps the patch's colours); no conflict; core-test 893/1053 (160 skipped), shell-test 1095/1098; its gate: .scratch/sketch/reorg/merge50, the numbers in PARDES.md (2026-11-21)
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/process.zig')
| -rw-r--r-- | test/process.zig | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/test/process.zig b/test/process.zig index e2a4f592..791a5b8e 100644 --- a/test/process.zig +++ b/test/process.zig @@ -496,10 +496,25 @@ pub const Files = struct { } }; -/// The files of the app a pty harness started. +/// The files of the app a pty harness started: its session's, named by +/// its pid, which is the app's own, or under PARDES_PAIR the app's child's +/// (the app the client, its session forked off: main.zig `pair`). pub fn of(gpa: std.mem.Allocator, h: *const eh.Harness) Files { var digits: [24]u8 = undefined; - return .init(gpa, std.fmt.bufPrint(&digits, "{d}", .{h.pid}) catch unreachable); + return .init(gpa, std.fmt.bufPrint(&digits, "{d}", .{if (std.c.getenv("PARDES_PAIR") != null) childOf(h.pid) else h.pid}) catch unreachable); +} + +/// A process's one child (Linux's /proc), or itself when it has none. +fn childOf(pid: libc.pid_t) libc.pid_t { + var path: [64]u8 = undefined; + var buf: [64]u8 = undefined; + const fd = libc.open(std.fmt.bufPrintSentinel(&path, "/proc/{d}/task/{d}/children", .{ pid, pid }, 0) catch unreachable, .{}); // two pids fit 64 + if (fd < 0) return pid; + defer _ = libc.close(fd); + const n = libc.read(fd, &buf, buf.len); + if (n <= 0) return pid; + var words = std.mem.tokenizeScalar(u8, buf[0..@intCast(n)], ' '); + return std.fmt.parseInt(libc.pid_t, words.next() orelse return pid, 10) catch pid; } /// `pardes --detach=<name>` in a throwaway root that is its HOME, runtime @@ -537,6 +552,9 @@ pub const Detached = struct { cap_len: usize = 0, /// Whether deinit removes the root (one passed in is its owner's). owns_root: bool = true, + /// Its tty pair has a daemon of the root's own (`startTty`, a Restored + /// pair's): this build, to end them both (`--kill-all`) at deinit. + tty_daemon: ?[:0]const u8 = null, files: Files, pub const Options = struct { @@ -697,6 +715,11 @@ pub const Detached = struct { pub fn deinit(d: *Detached) void { d.files.deinit(); d.child.deinit(); + if (d.tty_daemon) |exe| if (Child.spawn(&.{ exe, "--kill-all" }, .{ .root = d.root() })) |k| { + var killer = k; + _ = killer.wait(10_000); + killer.deinit(); + } else |_| {}; if (d.cap_len > 0) removeDir(d.captures()); if (d.owns_root) d.removeRoot(); } @@ -800,7 +823,13 @@ pub const Detached = struct { try argv.appendSlice(a, &.{ exe, "--tty", try std.fmt.allocPrintSentinel(a, "--9p={s}", .{name}, 0) }); try argv.appendSlice(a, args); try argv.append(a, d.abs(try std.fmt.allocPrint(a, "{s}.txt", .{name}))); - const env = try a.dupe([2][:0]const u8, &.{.{ "PARDES_DUMP", d.abs(try std.fmt.allocPrint(a, "{s}.dump.zon", .{name})) }}); + // A pair's (PARDES_PAIR) with a daemon of the root's own: a Restore + // lets its client go, and it joins again through it. + const dump = d.abs(try std.fmt.allocPrint(a, "{s}.dump.zon", .{name})); + const env = if (d.tty_daemon != null and std.c.getenv("PARDES_PAIR") != null) + try a.dupe([2][:0]const u8, &.{ .{ "PARDES_DUMP", dump }, .{ "PARDES_DAEMON", "on" } }) + else + try a.dupe([2][:0]const u8, &.{.{ "PARDES_DUMP", dump }}); var c = try Child.spawn(argv.items, .{ .root = d.root(), .env = env, .pty = .{ .log = d.abs(try std.fmt.allocPrint(a, "{s}.pty", .{name})) } }); errdefer c.deinit(); try c.waitPath(d.abs(try std.fmt.allocPrint(a, "pardes-9p-{s}.sock", .{name})), 10_000); |
