summaryrefslogtreecommitdiff
path: root/src/crash.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/crash.zig')
-rw-r--r--src/crash.zig6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/crash.zig b/src/crash.zig
index 34dc1b3d..a432fb87 100644
--- a/src/crash.zig
+++ b/src/crash.zig
@@ -34,6 +34,9 @@ pub const name = "crashes";
/// A panic handler is the one caller that cannot check whether its input is
/// still alive, so it does not borrow.
var dir_buf: [1024]u8 = undefined;
+
+/// The crash file's bound (see `record`).
+const max_log_bytes = 256 * 1024;
var dir_len: usize = 0;
/// Called where the launcher sets `Options.config_dir`. Ignores a path too long
@@ -109,6 +112,9 @@ pub fn record(msg: []const u8) void {
}, @as(std.c.mode_t, 0o600));
if (fd < 0) return;
defer _ = std.c.close(fd);
+ // Bounded: a file past `max_log_bytes` starts over, so it keeps the
+ // newest records rather than every crash since it was first made.
+ if (std.c.lseek(fd, 0, std.c.SEEK.END) > max_log_bytes) _ = std.c.ftruncate(fd, 0);
var w: std.Io.Writer = .fixed(&scratch);