summaryrefslogtreecommitdiff
path: root/core/dump.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/dump.zig')
-rw-r--r--core/dump.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/dump.zig b/core/dump.zig
index 683f043a..06a3eae5 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -399,6 +399,9 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes:
errdefer {
if (notes) |n| n.appendSlice(gpa, l.notes.items) catch {};
l.rollback();
+ // Its opens are what the load read: the rollback's, freed (and
+ // their count may be a damaged one, refused).
+ p.fs.opens_len = 0;
p.fs.deinit(gpa);
gpa.destroy(p);
}
@@ -475,6 +478,9 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?*
errdefer {
if (notes) |n| n.appendSlice(gpa, l.notes.items) catch {};
l.rollback();
+ // Its opens are what the load read: the rollback's, freed (and
+ // their count may be a damaged one, refused).
+ p.fs.opens_len = 0;
p.fs.deinit(gpa);
gpa.destroy(p);
}
@@ -1417,3 +1423,20 @@ test "optional GPU addon reload generation survives a replica dump" {
try std.testing.expectEqual(original.gen, restored.gen);
try std.testing.expectEqual(walk.digest(Kind.Slot, &original), walk.digest(Kind.Slot, &restored));
}
+
+test "a load refused after the core frees what a script's open held once: the rollback's, not the namespace's" {
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .mounts = &.{.{ .name = "peer", .dial = "/tmp/peer.sock" }} });
+ defer p.deinit();
+ _ = try p.setTestFile("x\n");
+ // A script's open of a file of command lines, its last line half
+ // written: bytes the load makes.
+ p.fs.opens[0] = .{ .node = 1, .what = .lines };
+ try p.fs.opens[0].pending.appendSlice(gpa, "Look half");
+ p.fs.opens_len = 1;
+ const bytes = try byteDump(p);
+ defer gpa.free(bytes);
+ // The mounts are read after the core: the same name dialled elsewhere
+ // refuses the load there.
+ try std.testing.expectError(error.MountConflict, load(gpa, .{ .mounts = &.{.{ .name = "peer", .dial = "/tmp/other.sock" }} }, bytes, null));
+}