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 +++---- runtime/upgrade.zig | 26 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) (limited to 'runtime') 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; diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index f59117ee..510c50ea 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -58,18 +58,28 @@ pub fn remember(args: []const [:0]const u8) void { }; } -/// Its path asked of the system (a readlink) and the file there now (a +/// Its path asked of the system (a readlink) and the file it runs (a /// stat), once: after the first frame, off a startup's way (the hosts' -/// loops; nothing is reinstalled within a frame of a start). +/// loops). A build can be installed at that path before then (a pair's +/// session, whose first pass comes after its client's first frame; a +/// loaded machine): Linux then names the path "PATH (deleted)", and the +/// file at the path is not the one it started from, the one it runs is. pub fn locate() void { if (located) return; located = true; - if (exe_len == 0) { - const n = std.process.executablePath(std.Io.Threaded.global_single_threaded.io(), &exe_buf) catch 0; - exe_buf[n] = 0; - exe_len = n; - } - if (exe()) |path| started_inode = inodeOf(path); + if (exe_len == 0) exe_len = if (startPath(&exe_buf)) |path| path.len else 0; + started_inode = if (builtin.os.tag == .linux) inodeOf("/proc/self/exe") else if (exe()) |path| inodeOf(path) else null; +} + +/// The path this process was started from, as the system names it, less +/// the " (deleted)" Linux adds once the file there was replaced (a +/// reinstall): the path is the path (what an Upgrade execs, and a daemon +/// started from here: daemon.zig `spawn`). +pub fn startPath(buf: *[4096:0]u8) ?[:0]const u8 { + const n = std.process.executablePath(std.Io.Threaded.global_single_threaded.io(), buf) catch return null; + const len = if (std.mem.endsWith(u8, buf[0..n], " (deleted)")) n - " (deleted)".len else n; + buf[len] = 0; + return buf[0..len :0]; } fn inodeOf(path: [:0]const u8) ?u64 { -- cgit v1.3