summaryrefslogtreecommitdiff
path: root/src/daemon.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 12:14:58 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commit4839c4b037d401393bbc87143d663e115c71242e (patch)
tree6d23e1cd9aaf89404dd53f03e6ada23588b42dcc /src/daemon.zig
parent77671575bd2f481651ea54e956ac5c7da8d63710 (diff)
downloadpardes-4839c4b037d401393bbc87143d663e115c71242e.tar.gz
pardes-4839c4b037d401393bbc87143d663e115c71242e.zip
idioms #2, formats that cannot overflow say so: a bufPrint or a fixed writer whose buffer provably holds the text (numbers, a 128-byte name, a short phrase) is catch unreachable with its reason, not a catch "" or a stand-in sentence nobody can reach, and dump.check takes its 256-byte why as such
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/daemon.zig')
-rw-r--r--src/daemon.zig19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/daemon.zig b/src/daemon.zig
index 6c0a0adf..ed558a52 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -759,13 +759,14 @@ const Daemon = struct {
fn kill(d: *Daemon, i: u8, named: ?[]const u8) void {
var line: [msg_max]u8 = undefined;
var w: std.Io.Writer = .fixed(&line);
- w.writeAll("ok") catch {};
+ // "ok" and max_conns pids fit msg_max.
+ w.writeAll("ok") catch unreachable;
var n: usize = 0;
for (&d.conns) |*s| if (s.fd >= 0 and s.kind != null) {
if (named) |want| if (!std.mem.eql(u8, s.named(), want)) continue;
s.killed = true;
_ = libc.kill(s.pid, .TERM);
- w.print(" {d}", .{s.pid}) catch {};
+ w.print(" {d}", .{s.pid}) catch unreachable;
n += 1;
};
if (named == null) {
@@ -783,7 +784,7 @@ const Daemon = struct {
fn list(d: *Daemon, i: u8) void {
var line: [msg_max]u8 = undefined;
var w: std.Io.Writer = .fixed(&line);
- w.print("daemon {d}\n", .{libc.getpid()}) catch {};
+ w.print("daemon {d}\n", .{libc.getpid()}) catch unreachable; // the first line of msg_max
for (&d.conns, 0..) |*s, k| if (s.fd >= 0 and s.kind != null) {
w.print("session {d} {t} {s} {s}\n", .{ s.pid, s.kind.?, if (s.detached) "detached" else "attached", s.named() }) catch break;
for (s.clients[0..s.nclients]) |pid| w.print("client {d}\n", .{pid}) catch break;
@@ -940,7 +941,7 @@ const Daemon = struct {
found = @intCast(i);
};
if (count == 1) {
- _ = std.fmt.bufPrint(why, "other {s}", .{d.conns[found.?].named()}) catch {};
+ _ = std.fmt.bufPrint(why, "other {s}", .{d.conns[found.?].named()}) catch unreachable; // a name of 128 fits 512
return null;
}
count = 0;
@@ -952,19 +953,19 @@ const Daemon = struct {
only = s;
};
if (found == null and sessions == 1) {
- _ = std.fmt.bufPrint(why, "other {s}", .{only.?.named()}) catch {};
+ _ = std.fmt.bufPrint(why, "other {s}", .{only.?.named()}) catch unreachable; // a name of 128 fits 512
return null;
}
}
if (count == 0 and others == 0) {
- w.writeAll("no no detached session is running") catch {};
+ w.writeAll("no no detached session is running") catch unreachable; // fits 511
return null;
}
if (count == 0) {
- w.print("no the detached session{s} running {s} {s}=<name>`", .{ if (others == 1) " is" else "s are", if (others == 1) "is" else "are each", other }) catch {};
+ w.print("no the detached session{s} running {s} {s}=<name>`", .{ if (others == 1) " is" else "s are", if (others == 1) "is" else "are each", other }) catch unreachable; // fits 511
return null;
}
- w.print("no {d} detached sessions are running; say which with --attach=<name>:", .{count}) catch {};
+ w.print("no {d} detached sessions are running; say which with --attach=<name>:", .{count}) catch unreachable; // fits 511
for (&d.conns) |*s| if (s.fd >= 0 and s.detached and s.kind == k) {
w.print(" {s}", .{s.named()}) catch {};
};
@@ -989,7 +990,7 @@ const Daemon = struct {
if (f.tag != @backingInt(wire.ClientTag.hello)) return refuse(r, "the first message is not a hello");
var why: [512]u8 = undefined;
const v = wire.helloVersion(f.payload) catch 0;
- if (v != wire.version) return refuse(r, std.fmt.bufPrint(&why, "this client speaks replica protocol {d}, and this daemon {d}: run the same pardes at both ends", .{ v, wire.version }) catch "another protocol");
+ if (v != wire.version) return refuse(r, std.fmt.bufPrint(&why, "this client speaks replica protocol {d}, and this daemon {d}: run the same pardes at both ends", .{ v, wire.version }) catch unreachable); // two numbers fit 512
const h = (wire.decodeClient(f.tag, f.payload) catch return refuse(r, "a malformed hello")).hello;
const target = for (&d.conns, 0..) |*c, i| {
if (c.fd >= 0 and c.kind != null and std.mem.eql(u8, c.named(), h.session)) break i;