diff options
Diffstat (limited to 'src/crash.zig')
| -rw-r--r-- | src/crash.zig | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/crash.zig b/src/crash.zig index 10d38591..a432fb87 100644 --- a/src/crash.zig +++ b/src/crash.zig @@ -23,7 +23,7 @@ const std = @import("std"); const builtin = @import("builtin"); const pardes = @import("pardes.zig"); -/// Beside `init`, so `Config` opens the directory that holds both. +/// The crash log's name, beside `init` in the configuration directory. pub const name = "crashes"; /// The config directory `config.User.load` resolved, COPIED rather than @@ -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 @@ -47,7 +50,7 @@ pub fn setDir(path: []const u8) void { /// Built at comptime out of the two halves main.zig's `--version` prints, and /// for the same reason: there is nothing here to format at runtime. A build -/// from a tarball says `pardes 0.0.1` rather than inventing a revision. +/// from a tarball says `pardes 0.1` rather than inventing a revision. const build_id = if (pardes.commit) |c| "pardes " ++ pardes.version ++ " (" ++ c ++ ")" else @@ -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); |
