diff options
Diffstat (limited to 'runtime/upgrade.zig')
| -rw-r--r-- | runtime/upgrade.zig | 26 |
1 files changed, 18 insertions, 8 deletions
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 { |
