summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/daemon.zig2
-rw-r--r--src/gui/gui.zig7
-rw-r--r--src/host_io.zig6
-rw-r--r--src/tty/tty.zig7
-rw-r--r--src/upgrade.zig50
5 files changed, 58 insertions, 14 deletions
diff --git a/src/daemon.zig b/src/daemon.zig
index 43f15c6c..785f4afd 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -1087,7 +1087,7 @@ pub fn serve(state: ?[]const u8) noreturn {
ninep_io.setCloexec(4);
const ignore: posix.Sigaction = .{ .handler = .{ .handler = posix.SIG.IGN }, .mask = posix.sigemptyset(), .flags = 0 };
for ([_]posix.SIG{ .PIPE, .HUP, .INT }) |sig| posix.sigaction(sig, &ignore, null);
- upgrade.remember(&.{});
+ upgrade.locate();
var d: Daemon = .{};
const given = if (state) |text| d.restore(text) else -1;
const replicas = if (given >= 0) given else listenReplicas();
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 24061251..e4d69281 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -2502,6 +2502,7 @@ fn localSession(
while (!core.quit) {
pardes.turn.bump(&pardes.turn.restores);
try core.pump(host);
+ upgrade.locate();
// Asked in the step (the word), done between steps: the session whole.
if (shell.upgrade_asked) |pane| shell.upgradeNow(pane);
// A window asked for again, or an adopted shell, from the daemon's
@@ -3138,7 +3139,10 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
in.close();
},
c.SDL_EVENT_WINDOW_CLOSE_REQUESTED => in.close(),
- c.SDL_EVENT_WINDOW_FOCUS_GAINED => in.post(.{ .focus = true }),
+ c.SDL_EVENT_WINDOW_FOCUS_GAINED => {
+ in.post(.{ .focus = true });
+ if (in.core) |core| upgrade.noticeNewer(core);
+ },
c.SDL_EVENT_WINDOW_FOCUS_LOST => in.post(.{ .focus = false }),
c.SDL_EVENT_WINDOW_MOUSE_LEAVE => {
g.pointer_present = false;
@@ -4060,7 +4064,6 @@ const Shell = struct {
if (!upgrade.writeDump(at, bytes)) break :failed std.fmt.bufPrint(&why, "Upgrade: the session's dump could not be written to {s}; it stays as it is", .{at[0..@min(at.len, 600)]}) catch "Upgrade: its dump could not be written";
rec.dump = at;
rec.old = upgrade.openSelf();
- host_io.Shell.unlinkOwnedRcs();
daemon.upgraded();
if (s.fs) |f| f.flushOut();
const err_words = upgrade.exec(s.gpa, path, -1, &rec);
diff --git a/src/host_io.zig b/src/host_io.zig
index 46ee9afc..c627d4ab 100644
--- a/src/host_io.zig
+++ b/src/host_io.zig
@@ -977,8 +977,10 @@ pub const Shell = struct {
while (std.c.readdir(dir)) |ent| {
const name = std.mem.sliceTo(@as([*:0]const u8, @ptrCast(&ent.name)), 0);
const pid = rcPid(name) orelse continue;
- if (pid == std.c.getpid()) continue;
- if (std.posix.errno(std.c.kill(pid, @fromBackingInt(@intCast(0)))) != .SRCH) continue;
+ // This pid's are this process's, but in an upgraded one: those
+ // were its old image's (upgrade.zig), and its own come after.
+ if (pid == std.c.getpid() and @import("upgrade.zig").resumed == null) continue;
+ if (pid != std.c.getpid() and std.posix.errno(std.c.kill(pid, @fromBackingInt(@intCast(0)))) != .SRCH) continue;
if (name.len >= 64 or n == dead.len) continue;
@memcpy(dead[n][0..name.len], name);
dead_len[n] = name.len;
diff --git a/src/tty/tty.zig b/src/tty/tty.zig
index ef7688bc..14dc8042 100644
--- a/src/tty/tty.zig
+++ b/src/tty/tty.zig
@@ -1564,6 +1564,7 @@ fn localSession(
while (!core.quit) {
pardes.turn.bump(&pardes.turn.restores);
try core.pump(host);
+ upgrade.locate();
// Asked in the step (the word), done between steps: the session whole.
if (sh.upgrade_asked) |pane| sh.upgradeNow(pane);
// A terminal (`pardes --attach`) or an adopted shell, handed on by
@@ -1973,7 +1974,6 @@ const Shell = struct {
};
popped = true;
unlinkKittyShm();
- host_io.Shell.unlinkOwnedRcs();
daemon.upgraded();
if (s.fs) |f| f.flushOut();
const err_words = upgrade.exec(s.gpa, path, -1, &rec);
@@ -2261,7 +2261,10 @@ const Shell = struct {
},
.attach => |a| s.attachTerminal(a.tty, a.stub, null),
.adopted => |a| s.adoptShell(a.pid, a.fd),
- .focus_in => core.update(.{ .focus = true }),
+ .focus_in => {
+ core.update(.{ .focus = true });
+ upgrade.noticeNewer(core);
+ },
.focus_out => {
core.update(.pointer_leave);
core.update(.{ .focus = false });
diff --git a/src/upgrade.zig b/src/upgrade.zig
index c49d2370..49e8aff5 100644
--- a/src/upgrade.zig
+++ b/src/upgrade.zig
@@ -32,21 +32,53 @@ var exe_buf: [4096:0]u8 = undefined;
var exe_len: usize = 0;
/// The arguments it was started with (an upgrade's record left out).
var given: []const [:0]const u8 = &.{};
+/// The file at that path when it started, and the newer one last said.
+var started_inode: ?u64 = null;
+var told_inode: ?u64 = null;
-/// Its path asked of the system now, at its start (one readlink), and its
-/// arguments kept; an upgraded process takes the path its record names
-/// (the system would name a fallback's old binary, deleted).
+var located = false;
+
+/// Its arguments kept, at its start; an upgraded process's path is the one
+/// its record names (the system would name a fallback's old binary,
+/// deleted).
pub fn remember(args: []const [:0]const u8) void {
given = if (args.len > 1 and std.mem.startsWith(u8, args[1], flag)) args[2..] else if (args.len > 0) args[1..] else &.{};
if (resumed) |*rec| if (rec.exe.len > 0 and rec.exe.len < exe_buf.len) {
@memcpy(exe_buf[0..rec.exe.len], rec.exe);
exe_buf[rec.exe.len] = 0;
exe_len = rec.exe.len;
- return;
};
- const n = std.process.executablePath(std.Io.Threaded.global_single_threaded.io(), &exe_buf) catch 0;
- exe_buf[n] = 0;
- exe_len = n;
+}
+
+/// Its path asked of the system (a readlink) and the file there now (a
+/// stat), once: after the first frame, off a startup's way (the hosts'
+/// loops; nothing is reinstalled within a frame of a start).
+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);
+}
+
+fn inodeOf(path: [:0]const u8) ?u64 {
+ const st = std.Io.Dir.cwd().statFile(std.Io.Threaded.global_single_threaded.io(), path, .{}) catch return null;
+ return @intCast(st.inode);
+}
+
+/// A newer build installed at that path since this process started, said
+/// in a line, once a build: asked at a focus-in, where one comes back from
+/// rebuilding (a stat). ponytail: explicit only, no watch and no automatic
+/// upgrade.
+pub fn noticeNewer(core: *pardes.Pardes) void {
+ const was = started_inode orelse return;
+ const now = inodeOf(exe() orelse return) orelse return;
+ if (now == was or told_inode == now) return;
+ told_inode = now;
+ core.setMessage(core.active, "a newer pardes is installed: Upgrade (SPC s U) moves this session onto it");
}
pub fn exe() ?[:0]const u8 {
@@ -336,6 +368,10 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op
var buf: [700]u8 = undefined;
if (loaded) |p| {
_ = libc.unlink(path);
+ // The binary it replaced, let go: held, its file (deleted) would
+ // keep its blocks for as long as this session runs.
+ if (rec.old >= 0) _ = libc.close(rec.old);
+ rec.old = -1;
p.setMessage(p.active, if (rec.refused.len > 0)
std.fmt.bufPrint(&buf, "Upgrade: the new build could not load this session ({s}); it goes on as {s}", .{ rec.refused[0..@min(rec.refused.len, 200)], version_line }) catch "Upgrade: the new build could not load this session; it goes on as before"
else