diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 19:55:02 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 19:55:02 -0300 |
| commit | 2ab05b536bc3b063666b5aaab497157adc2a9120 (patch) | |
| tree | 4b796e6abaf7658294d2b6cbb5d35e0210b88b40 /core/Addon.zig | |
| parent | e4f99d2370c8b44e76b541826d91356d86090f53 (diff) | |
| parent | 786cddd24e2be36d30847300075cec8c45d1b0ca (diff) | |
| download | pardes-2ab05b536bc3b063666b5aaab497157adc2a9120.tar.gz pardes-2ab05b536bc3b063666b5aaab497157adc2a9120.zip | |
integration: the regular-expression fixes with the fixes the real loops asked for: pardes-regex-2 (mvzr's reads past a pattern cut short patched as it is fetched; the leak of a pattern that does not compile; the soak's corpus check comparing what is visible) and pardes-draw-2 (a step's notice bands and a markdown text's tables made from the step's own state, never from the last frame; a load under way in another live process no crash; an idle pair silent), merged without a conflict; gates in the coordinator's ledger
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Addon.zig')
| -rw-r--r-- | core/Addon.zig | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/core/Addon.zig b/core/Addon.zig index d52462e0..54d1da00 100644 --- a/core/Addon.zig +++ b/core/Addon.zig @@ -445,11 +445,12 @@ fn markPath(buf: []u8, data: []const u8, comptime name: []const u8) ?[:0]const u return std.fmt.bufPrintSentinel(buf, "{s}/" ++ name, .{data}, 0) catch null; } -/// The load of `path` under way, on disk until `unmark`. +/// The load of `path` under way in this process, on disk until `unmark`: +/// its name says whose (every pardes of the user shares the directory). fn mark(data: []const u8, path: []const u8) void { if (data.len == 0) return; var buf: [4096]u8 = undefined; - const at = markPath(&buf, data, "addon-loading") orelse return; + const at = std.fmt.bufPrintSentinel(&buf, "{s}/addon-loading.{d}", .{ data, std.c.getpid() }, 0) catch return; const f = std.c.fopen(at, "w") orelse return; _ = std.c.fwrite(path.ptr, 1, path.len, f); _ = std.c.fclose(f); @@ -468,16 +469,33 @@ fn unmark() void { marked_len = 0; } -/// The library that crashed its session's load: a mark left by a start -/// that never finished one becomes `addon-crashed`, which it stays. +/// The library that crashed its session's load: a mark left by a process +/// that is gone, its load never finished, becomes `addon-crashed`, which it +/// stays. A live one's is a load under way (a client starting while its +/// session loads the same library), no crash: taken for one, the client +/// never ran the kind and every start after skipped it. fn crashedPath(data: []const u8) Kind.Buf(4096) { var out: Kind.Buf(4096) = .{}; if (data.len == 0) return out; - var lbuf: [4096]u8 = undefined; var cbuf: [4096]u8 = undefined; - const loading = markPath(&lbuf, data, "addon-loading") orelse return out; const crashed = markPath(&cbuf, data, "addon-crashed") orelse return out; - if (std.c.access(loading, 0) == 0) _ = std.c.rename(loading, crashed); + var dbuf: [4096]u8 = undefined; + const dz = std.fmt.bufPrintSentinel(&dbuf, "{s}", .{data}, 0) catch return out; + if (std.c.opendir(dz)) |d| { + defer _ = std.c.closedir(d); + while (std.c.readdir(d)) |e| { + const name = std.mem.sliceTo(@as([*:0]const u8, @ptrCast(&e.name)), 0); + if (!std.mem.startsWith(u8, name, "addon-loading")) continue; + // `addon-loading` alone is an older build's, whose is not known. + if (name.len > "addon-loading".len) { + const pid = std.fmt.parseInt(std.c.pid_t, name["addon-loading.".len..], 10) catch continue; + if (std.posix.errno(std.c.kill(pid, @fromBackingInt(@intCast(0)))) != .SRCH) continue; + } + var lbuf: [4096]u8 = undefined; + const loading = std.fmt.bufPrintSentinel(&lbuf, "{s}/{s}", .{ data, name }, 0) catch continue; + _ = std.c.rename(loading, crashed); + } + } out.set(readSmall(crashed).slice()); return out; } @@ -916,6 +934,36 @@ test "addon reload gives migration the old record version and saves the new vers try std.testing.expectEqual(@as(u32, 2), slot.version); } +test "a load under way in another live process is no crash: a start meanwhile lists the addon, and the mark stays the loader's" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const data = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + try tmp.dir.createDirPath(std.testing.io, "addons"); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "addons/game.so", .data = "not a library" }); + var lib_buf: [4096]u8 = undefined; + const lib = try std.fmt.bufPrint(&lib_buf, "{s}/addons/game.so", .{data}); + var dir_buf: [4096]u8 = undefined; + const dir = try std.fmt.bufPrint(&dir_buf, "{s}/addons", .{data}); + // In order, as two processes of the user went under load (daemon.py + // --games): one marks its load of the library (this process, alive), + // another starts its scan before it unmarks. + mark(data, lib); + defer unmark(); + nfound = 0; + scanDir(data, dir, crashedPath(data).slice()); + defer nfound = 0; + try std.testing.expectEqualStrings(lib, found[0].path); + try std.testing.expect(std.mem.indexOf(u8, found[0].why, "crashed") == null); + try std.testing.expectError(error.FileNotFound, tmp.dir.access(std.testing.io, "addon-crashed", .{})); + // The loader gone with its mark left: a crash, skipped. + var name_buf: [64]u8 = undefined; + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = try std.fmt.bufPrint(&name_buf, "addon-loading.{d}", .{std.math.maxInt(i32)}), .data = lib }); + nfound = 0; + scanDir(data, dir, crashedPath(data).slice()); + try std.testing.expect(std.mem.startsWith(u8, found[0].why, "skipped: it crashed its last load")); +} + test "a load that never finished is skipped at the next start, and every start after, until a load asks for it" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); |
