From bbae7225e939daf4b6360d3de7af06c0fd95ce8d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 06:21:57 -0300 Subject: pair: the process suite as pairs from 13 of 145 failing to 7 that stay (the goldens of one cause, open): the harness dials a pair's session, the launched client's child (test/process.zig `of`, `childOf`: it dialled the launched pid's socket); a Restore in a pair no daemon keeps is refused in words, as its Upgrade is (P42: runtime/session.zig `restore`: it let the client go and the session ended with its last link), and the three cases that Restore a pair run it with a daemon of their own root's (tty.zig `privateDaemon`, e2e_harness `PARDES_HARNESS_DAEMON`, process.zig `Detached.tty_daemon`, ended by `--kill-all` at its deinit); a pair's launch with no terminal says what the own path says and forks no session (main.zig `pair`, `noTerminal`: it said "pardes: NoDevice" after forking one); a terminal client ended by TERM or HUP dies of the signal once its goodbye is said and its terminal put back, as the own path's stub does (tui.zig `dieOfQuitSignal`: it exited 0 since pair-3), and the kill test takes a pair's hang-up as the close P36 ruled; PARDES_PAIR=1 process-test 8 of 145 (7 goldens of one family: resizes=2, a terminal panned in a view shorter than the one that sized it, a restored terminal's history; winch once), without the variable 0 of 145 Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/tui/tui.zig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'dev') diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 09704424..7e5a75fb 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -731,6 +731,10 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, posix.sigaddset(&winch_set, posix.SIG.HUP); posix.sigaddset(&winch_set, posix.SIG.TERM); hangup_quits = true; + // Last of all, after its goodbye and its terminal put back: dead of the + // TERM or HUP that ended it, as the own path's stub dies (the shell's + // $? is 128+N), not exit 0. + defer dieOfQuitSignal(); if (comptime builtin.os.tag == .freebsd) posix.sigaction(.WINCH, &.{ .handler = .{ .handler = keepSignal }, .mask = posix.sigemptyset(), .flags = 0 }, null); posix.sigprocmask(posix.SIG.BLOCK, &winch_set, null); @@ -808,6 +812,7 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, var status: c_int = 0; while (libc.waitpid(@intCast(start.joined.pid), &status, 0) < 0 and libc.errno(-1) == .INTR) {} } + dieOfQuitSignal(); std.process.exit(code); }, .failed => { @@ -1954,6 +1959,22 @@ fn keepSignal(_: posix.SIG) callconv(.c) void {} /// A replica client's (`runClient`): a hangup or a TERM is its end. var hangup_quits = false; +/// The signal a client's `.quit` came of (`winchWatch`), 0 for none. +var quit_signal: std.atomic.Value(c_int) = .init(0); + +/// A client ended by TERM or HUP dies of it, its goodbye said and its +/// terminal put back first; no other way out. +fn dieOfQuitSignal() void { + const sig: posix.SIG = @enumFromInt(quit_signal.load(.acquire)); + if (@backingInt(sig) == 0) return; + const default: posix.Sigaction = .{ .handler = .{ .handler = posix.SIG.DFL }, .mask = posix.sigemptyset(), .flags = 0 }; + posix.sigaction(sig, &default, null); + var set = posix.sigemptyset(); + posix.sigaddset(&set, sig); + posix.sigprocmask(posix.SIG.UNBLOCK, &set, null); + _ = std.c.raise(sig); +} + fn winchWatch(loop: *Loop) void { var set = posix.sigemptyset(); posix.sigaddset(&set, posix.SIG.WINCH); @@ -1965,6 +1986,7 @@ fn winchWatch(loop: *Loop) void { // The terminals are the loop's: it asks each its size, and takes a // hangup as the end of the one that hung up. const ev: Msg = if (sig == @backingInt(posix.SIG.WINCH)) .winched else if (hangup_quits) .quit else .hangup; + if (ev == .quit) quit_signal.store(sig, .release); loop.postEvent(ev) catch {}; } } -- cgit v1.3