From 5a864360e6b0e72fc9734ab76c085a38fe1e60ba Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 04:30:17 -0300 Subject: upgrade, daemon: the start path less Linux's " (deleted)", and the file it started from the one it runs, whenever it is first asked: a session looked its start path up once, after its first pass round its loop (runtime/upgrade.zig `locate`: a readlink of /proc/self/exe and a stat OF THE PATH, "nothing is reinstalled within a frame of a start"), and a pair's session draws no frame: its first pass can come after its client's first frame, when a build is installed there (pair_exec_reaps, installed to ReleaseSafe on one CPU, 1 of 80 after the change before: "the session exec'd" not in 60 s, the session's own words "Upgrade: …/bin/pardes (deleted) would not start; this session stays as it is"); looked up after a reinstall the path is "PATH (deleted)" (the Upgrade execs that name, refused) and the "started" inode is the new file's (`replaced` and `newer` then say no newer build: a client that looked late does not exec at an Upgrade, and the newer-build notice never comes); and a daemon started by a process whose file was replaced (daemon.zig `spawn`, its own readlink: a pair's client at its start, a session whose daemon died after a reinstall) execs "PATH (deleted)" and none starts ("Upgrade: no daemon keeps this session, so its client could not join it again"); a user can hit both: a build installed in the first moments of a session, then an Upgrade, refused; a build installed, then the daemon killed or dead: no session can start the next; THE TEST that makes it come every time: test/daemon.py `pair_exec_reaps(new, new, early=True)` (run by every `--upgrade`: the same build installed again at once, before the session looked its path up and as the client starts the daemon: the session must exec it and the client, its build the session's still, join again in place): on pardes-m63-base 0 of 20 (ReleaseSafe on CPUs 5,13 and Debug: every one "no daemon keeps this session"); now `upgrade.startPath` (the path as the system names it, less " (deleted)") is what `locate` keeps and what `spawn` execs, and the started inode is the file the process runs (a stat of /proc/self/exe on Linux; the path's on FreeBSD as before); after (loads 4.4-9.0): the early row 20 of 20 on Debug (CPUs 5,13) and on ReleaseSafe once its expectation was the same-build rejoin, pair_exec_reaps 120 of 120 (Debug to ReleaseSafe, ReleaseSafe to Debug, installed to ReleaseSafe; 20 each on CPU 5 and on CPUs 5,13) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- runtime/daemon.zig | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'runtime/daemon.zig') diff --git a/runtime/daemon.zig b/runtime/daemon.zig index 595d5107..a964eb0b 100644 --- a/runtime/daemon.zig +++ b/runtime/daemon.zig @@ -241,9 +241,8 @@ extern "c" fn close_range(first: c_uint, last: c_uint, flags: c_int) c_int; /// twice), on the listener and the lock as fds 3 and 4. fn spawn(listener: c_int, lock: c_int) bool { var exe_buf: [4096:0]u8 = undefined; - const n = std.process.executablePath(std.Io.Threaded.global_single_threaded.io(), &exe_buf) catch return false; - exe_buf[n] = 0; - const argv = [_:null]?[*:0]const u8{ &exe_buf, "--daemon", null }; + const exe = upgrade.startPath(&exe_buf) orelse return false; + const argv = [_:null]?[*:0]const u8{ exe, "--daemon", null }; const first = libc.fork(); if (first < 0) return false; if (first == 0) { @@ -268,7 +267,7 @@ fn spawn(listener: c_int, lock: c_int) bool { }; if (null_fd > 4) _ = libc.close(null_fd); _ = libc.chdir("/"); - _ = libc.execve(&exe_buf, &argv, @ptrCast(libc.environ)); + _ = libc.execve(exe, &argv, @ptrCast(libc.environ)); libc._exit(127); } var status: c_int = 0; -- cgit v1.3 From 0477ea526bb22604ec51c7d58cf566952fe2fdf0 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 09:02:22 -0300 Subject: daemon: the stub dies of its session's KILL as of any other signal, not of an abort: a terminal's session killed outright (kill -9, the OOM killer) left its stub, the job the shell waits on, dead of SIGABRT (-6, $? 134) with a Zig trace printed on the user's terminal (pardes-pair-13's z6/sees.py on pardes-m63-base's Debug build: `std/posix.zig:954 in sigaction: .INVAL => unreachable` from runtime/daemon.zig:680 `stubWait`), because stubWait re-raises the signal its session died of after setting that signal's action to the default, and KILL's action cannot be set (EINVAL, which std's posix.sigaction takes as unreachable); a user of the installed build can hit it (the own path is its default); now the action is set for any signal but KILL (its default already) and the stub dies of the KILL (-9, $? 137); the row `killed_session` (test/daemon.py, plain mode, both ways by its one switch): the session killed with KILL, the job ends with no trace on its terminal, -9 on the own path and 1 for a pair's client (let go: "'x' let this client go"); sees.py after: the own path -9 and no trace; core-test 931/1095 (164 skipped), shell-test 1137/1140 (3 skipped), process-test 0 of 146 both ways (with the next change, loads 2.1-11) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- runtime/daemon.zig | 9 +++++++-- test/daemon.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) (limited to 'runtime/daemon.zig') diff --git a/runtime/daemon.zig b/runtime/daemon.zig index a964eb0b..97941a12 100644 --- a/runtime/daemon.zig +++ b/runtime/daemon.zig @@ -676,8 +676,13 @@ fn stubWait(session: libc.pid_t, pipe: c_int) noreturn { if (libc.W.IFEXITED(s)) libc._exit(@intCast(libc.W.EXITSTATUS(s))); if (libc.W.IFSIGNALED(s)) { const sig = libc.W.TERMSIG(s); - const default: posix.Sigaction = .{ .handler = .{ .handler = posix.SIG.DFL }, .mask = posix.sigemptyset(), .flags = 0 }; - posix.sigaction(sig, &default, null); + // A KILL's action is its default already and cannot be set + // (EINVAL: posix.sigaction's unreachable, the stub aborting with a + // trace on the terminal); any other is put back to it first. + if (sig != .KILL) { + const default: posix.Sigaction = .{ .handler = .{ .handler = posix.SIG.DFL }, .mask = posix.sigemptyset(), .flags = 0 }; + posix.sigaction(sig, &default, null); + } _ = libc.raise(sig); } libc._exit(1); diff --git a/test/daemon.py b/test/daemon.py index 7f1adfdb..34c4c7a6 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -2870,6 +2870,46 @@ def cpu_ticks(pid): return int(stat[11]) + int(stat[12]) +def killed_session(binary): + """A terminal's session killed outright (KILL, as the OOM killer does): + the job its terminal waits on ends with it, and says nothing of its own + (no trace): the own path's stub dead of the same signal, as a job is + (daemon.zig `stubWait`, which aborted re-raising a KILL); a pair's + client let go of its session, 1.""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='rk-', dir=scratch)) + env = base_env() + env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), + TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') + (root / 'config' / 'pardes').mkdir(parents=True) + (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') + notes = root / 'notes.txt' + notes.write_text(''.join(f'line {i} of the notes\n' for i in range(30))) + t = Term(30, 100) + try: + c = t.spawn([binary, '--9p=k', str(notes)], env) + sock = root / 'pardes-9p-k.sock' + wait_for('the socket', sock.exists) + with Client(sock) as nine: + session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid']) + wait_for('drawn', lambda: b'line 3 of the notes' in t.text(), timeout=30) + os.kill(session, signal.SIGKILL) + code = c.wait(timeout=30) + said = t.last() + assert b'panic' not in said and b'unreachable' not in said, said[-1500:] + assert code == (1 if WITH_PAIR else -signal.SIGKILL), (code, said[-600:]) + print(f'killed session: its terminal\'s job ended {code} with it, no trace') + finally: + for p in processes(root): + try: + os.kill(p, signal.SIGKILL) + except OSError: + pass + t.close() + shutil.rmtree(root, ignore_errors=True) + + def kitty_image(binary, secs=5): """A plain attach watching a terminal in which a program shows a kitty image (the corpus's scene 10's: 8x8 RGB, 10x4 cells): it @@ -4132,3 +4172,4 @@ if __name__ == '__main__': gui_pair(args[0]) else: main(sys.argv[1], int(sys.argv[2]) if len(sys.argv) > 2 else 50) + killed_session(sys.argv[1]) -- cgit v1.3