summaryrefslogtreecommitdiff
path: root/src/crash.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
committerGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
commit6d8da8721141284cf33bb901168b26135893eb86 (patch)
tree791d63401d4e85fbca1d597a8ce0326e70efd545 /src/crash.zig
parentefd43a3a2cf03bb741366331158b368abf9ac583 (diff)
parentbf6810a8f9d6cc82050e7d9c0cfb06358301b574 (diff)
downloadpardes-6d8da8721141284cf33bb901168b26135893eb86.tar.gz
pardes-6d8da8721141284cf33bb901168b26135893eb86.zip
Merge latest upstream into the macOS branch for Zig 0.17
Retain the macOS branch history and local Acme selection color while adopting upstream's current core and platform changes. Pin Zig and ZLS to 0.17.0, and fetch the existing zstbi compatibility commit through upstream after its original fork was removed.
Diffstat (limited to 'src/crash.zig')
-rw-r--r--src/crash.zig10
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);