summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:51:07 -0300
committerGabriel Schneider <[email protected]>2026-11-05 09:54:56 -0300
commit2ffc4abedcef7f077ebc7290b653415243da0975 (patch)
tree8858b8ee8bd61234a305df359e9ef193f6085e29 /src
parent617cdcc8999cefdfd785b80026805cef51d96b08 (diff)
downloadpardes-2ffc4abedcef7f077ebc7290b653415243da0975.tar.gz
pardes-2ffc4abedcef7f077ebc7290b653415243da0975.zip
processes: small ones (main's version text from upgrade.version_line and waitForDel's unused io; daemon's find returns null with its words, drop takes the slot alone, send, recv, Got and setName are private; replica's Joining is the daemon's and PARDES_REPLICA_LAG_KB, which nothing sets, goes; host_io's dead line variable; Handover's own readdir is std.c's)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
-rw-r--r--src/Handover.zig4
-rw-r--r--src/daemon.zig55
-rw-r--r--src/host_io.zig3
-rw-r--r--src/main.zig10
-rw-r--r--src/replica.zig6
5 files changed, 33 insertions, 45 deletions
diff --git a/src/Handover.zig b/src/Handover.zig
index 549e4d58..d245a6af 100644
--- a/src/Handover.zig
+++ b/src/Handover.zig
@@ -385,8 +385,6 @@ fn carry(io: std.Io, job: *Job) void {
job.post(job.post_ctx, job.seq, false, "the new window did not come up in 15 s");
}
-extern "c" fn readdir(dir: *libc.DIR) ?*libc.dirent;
-
/// The registry entry of the window the pointer was let go over, asked of
/// every window by its `status` (`pointer in`): Wayland tells no client
/// where any window is, only whether the pointer is over its own, and the
@@ -404,7 +402,7 @@ fn windowUnderPointer(io: std.Io, job: *Job, out: *[512]u8) std.Io.Cancelable!?[
const dir = libc.opendir(reg) orelse return null;
defer _ = libc.closedir(dir);
var windows: usize = 0;
- while (readdir(dir)) |ent| {
+ while (libc.readdir(dir)) |ent| {
const name = std.mem.sliceTo(&ent.name, 0);
if (name.len == 0 or name[0] == '.') continue;
const entry = std.fmt.bufPrintSentinel(out, "{s}/{s}", .{ reg, name }, 0) catch continue;
diff --git a/src/daemon.zig b/src/daemon.zig
index 7d2ca9b4..3b1cfcd7 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -73,7 +73,7 @@ fn cmsgSpace(n: usize) usize {
return data_off + std.mem.alignForward(usize, n * @sizeOf(c_int), @sizeOf(usize));
}
-pub fn send(fd: c_int, words: []const u8, fds: []const c_int) bool {
+fn send(fd: c_int, words: []const u8, fds: []const c_int) bool {
std.debug.assert(words.len > 0 and fds.len <= max_fds);
var iov = [_]posix.iovec_const{.{ .base = words.ptr, .len = words.len }};
var cbuf: [cmsgSpace(max_fds)]u8 align(@alignOf(libc.cmsghdr)) = undefined;
@@ -93,10 +93,10 @@ pub fn send(fd: c_int, words: []const u8, fds: []const c_int) bool {
}
}
-pub const Got = struct { words: []const u8, fds: [max_fds]c_int = undefined, nfds: usize = 0 };
+const Got = struct { words: []const u8, fds: [max_fds]c_int = undefined, nfds: usize = 0 };
/// The next message, its fds close-on-exec; null at the end of the link.
-pub fn recv(fd: c_int, buf: []u8) ?Got {
+fn recv(fd: c_int, buf: []u8) ?Got {
var iov = [_]posix.iovec{.{ .base = buf.ptr, .len = buf.len }};
var cbuf: [cmsgSpace(max_fds)]u8 align(@alignOf(libc.cmsghdr)) = undefined;
var msg: libc.msghdr = .{ .name = null, .namelen = 0, .iov = &iov, .iovlen = 1, .control = &cbuf, .controllen = cbuf.len, .flags = 0 };
@@ -305,7 +305,7 @@ pub fn kept() bool {
/// The name a session goes by: its 9P socket's (`--9p=`, `--detach=`), else
/// its pid, as ninep_io.start names it.
-pub fn setName(named: []const u8) void {
+fn setName(named: []const u8) void {
const n = if (named.len != 0)
std.fmt.bufPrint(&name_buf, "{s}", .{named[0..@min(named.len, name_buf.len)]}) catch unreachable
else
@@ -693,6 +693,11 @@ const Held = struct {
owner: ?u8 = null,
};
+fn drop(h: *Held) void {
+ _ = libc.close(h.fd);
+ h.* = .{};
+}
+
/// A replica's connection until its hello is whole: read no further than
/// the hello, so what follows it is the session's to read.
const Replica = struct {
@@ -714,12 +719,6 @@ const Daemon = struct {
return true;
}
- fn drop(d: *Daemon, h: *Held) void {
- _ = d;
- _ = libc.close(h.fd);
- h.* = .{};
- }
-
fn hangUp(d: *Daemon, i: u8) void {
const c = &d.conns[i];
const killed = c.killed;
@@ -728,7 +727,7 @@ const Daemon = struct {
// Whatever it still held, it died holding: kept for an Adopt, unless
// it was killed on purpose, when its shells hang up with it.
for (&d.held) |*h| if (h.fd >= 0 and h.owner == i) {
- if (killed) d.drop(h) else h.owner = null;
+ if (killed) drop(h) else h.owner = null;
};
}
@@ -748,7 +747,7 @@ const Daemon = struct {
n += 1;
};
if (named == null) {
- for (&d.held) |*h| if (h.fd >= 0 and h.owner == null) d.drop(h);
+ for (&d.held) |*h| if (h.fd >= 0 and h.owner == null) drop(h);
} else if (n == 0) {
var why: [256]u8 = undefined;
return d.reply(i, std.fmt.bufPrint(&why, "no no session called '{s}'", .{named.?}) catch "no no such session", &.{});
@@ -819,11 +818,11 @@ const Daemon = struct {
}
if (std.mem.eql(u8, verb, "close")) {
const pid = std.fmt.parseInt(libc.pid_t, words.next() orelse "", 10) catch return;
- for (&d.held) |*h| if (h.fd >= 0 and h.pid == pid and h.owner == i) d.drop(h);
+ for (&d.held) |*h| if (h.fd >= 0 and h.pid == pid and h.owner == i) drop(h);
return;
}
if (std.mem.eql(u8, verb, "quit")) {
- for (&d.held) |*h| if (h.fd >= 0 and h.owner == i) d.drop(h);
+ for (&d.held) |*h| if (h.fd >= 0 and h.owner == i) drop(h);
return;
}
if (std.mem.eql(u8, verb, "upgrade")) {
@@ -854,10 +853,8 @@ const Daemon = struct {
const k = std.meta.stringToEnum(Kind, words.next() orelse "") orelse return d.reply(i, "no bad attach", &.{});
const wanted_name = std.mem.trim(u8, words.rest(), " ");
var why: [512]u8 = undefined;
- const target = d.find(k, wanted_name, &why) catch |err| return d.reply(i, switch (err) {
- // "other <name>": the client joins it through the replica socket.
- error.Said, error.Other => std.mem.sliceTo(&why, 0),
- }, &.{});
+ // "other <name>": the client joins it through the replica socket.
+ const target = d.find(k, wanted_name, &why) orelse return d.reply(i, std.mem.sliceTo(&why, 0), &.{});
const t = &d.conns[target];
if (!send(t.fd, "attach", got.fds[0..got.nfds])) {
d.hangUp(target);
@@ -870,9 +867,9 @@ const Daemon = struct {
}
/// The detached session of kind `k` called `wanted_name`, or the one
- /// there is when it is empty; else why not, in `why` (0-terminated).
- /// One of the other kind is error.Other, `why` "other <its name>".
- fn find(d: *Daemon, k: Kind, wanted_name: []const u8, why: *[512]u8) error{ Said, Other }!u8 {
+ /// there is when it is empty; else null, and why not in `why`
+ /// (0-terminated): "other <its name>" for one of the other kind.
+ fn find(d: *Daemon, k: Kind, wanted_name: []const u8, why: *[512]u8) ?u8 {
@memset(why, 0);
const other: []const u8 = switch (k) {
.tty => "a window: attach it with `pardes-gui --attach",
@@ -882,13 +879,13 @@ const Daemon = struct {
for (&d.conns, 0..) |*s, i| if (s.fd >= 0 and s.kind != null and std.mem.eql(u8, s.named(), wanted_name)) {
if (s.kind.? != k) {
_ = std.fmt.bufPrint(why, "other {s}", .{wanted_name}) catch {};
- return error.Other;
+ return null;
}
// Attached already: the session takes another view.
- return @intCast(i);
+ return @as(u8, @intCast(i));
};
_ = std.fmt.bufPrint(why, "no no session called '{s}'", .{wanted_name}) catch {};
- return error.Said;
+ return null;
}
var found: ?u8 = null;
var count: usize = 0;
@@ -920,22 +917,22 @@ const Daemon = struct {
};
if (found == null and sessions == 1) {
_ = std.fmt.bufPrint(why, "other {s}", .{only.?.named()}) catch {};
- return error.Other;
+ return null;
}
}
if (count == 0 and others == 0) {
w.writeAll("no no detached session is running") catch {};
- return error.Said;
+ 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 {};
- return error.Said;
+ return null;
}
w.print("no {d} detached sessions are running; say which with --attach=<name>:", .{count}) catch {};
for (&d.conns) |*s| if (s.fd >= 0 and s.detached and s.kind == k) {
w.print(" {s}", .{s.named()}) catch {};
};
- return error.Said;
+ return null;
}
/// More of a replica's hello; once it is whole, the connection refused
@@ -1189,7 +1186,7 @@ pub fn serve(state: ?[]const u8) noreturn {
}
for (fds[held_at..n], held_of[held_at..n]) |pfd, i| {
if (pfd.revents == 0 or d.held[i].fd != pfd.fd) continue;
- d.drop(&d.held[i]);
+ drop(&d.held[i]);
}
if (d.upgrade_asked) {
d.upgrade_asked = false;
diff --git a/src/host_io.zig b/src/host_io.zig
index 21f6387b..a904f4a4 100644
--- a/src/host_io.zig
+++ b/src/host_io.zig
@@ -1812,12 +1812,11 @@ pub const ChildEnv = struct {
exported_state[i] = .cleared;
return;
};
- const line = std.fmt.bufPrintSentinel(&exported_line[i], "{s}={s}", .{ var_name, v }, 0) catch {
+ _ = std.fmt.bufPrintSentinel(&exported_line[i], "{s}={s}", .{ var_name, v }, 0) catch {
exported_state[i] = .cleared;
return;
};
exported_state[i] = .set;
- _ = line;
}
/// What children are told for `var_name`, as `exportVar` left it; null
diff --git a/src/main.zig b/src/main.zig
index 58f9541a..3dec406c 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -228,8 +228,7 @@ fn forwardWords(err: anyerror, buf: []u8) []const u8 {
/// pane `path` landed in (the one it already had, if open), then /log
/// followed on one connection until that pane's `del` -- exit 0 -- or the
/// connection ends with the session -- exit 1.
-fn waitForDel(io: std.Io, gpa: std.mem.Allocator, dial: []const u8, path: []const u8, known: ?u32) noreturn {
- _ = io;
+fn waitForDel(gpa: std.mem.Allocator, dial: []const u8, path: []const u8, known: ?u32) noreturn {
// The pane this launch made (a name not there yet), or the one its
// look answered, is known by its serial; one the look answered none
// for is found by its file. Found by none after the look went there,
@@ -319,10 +318,7 @@ fn die(io: std.Io, comptime fmt: []const u8, args: anytype) noreturn {
/// The second line is what a replica's build must share with its session's
/// (wire.zig `semantics`).
-const version_text = (if (pardes.commit) |c|
- "pardes " ++ pardes.version ++ " (" ++ c ++ ")\n"
-else
- "pardes " ++ pardes.version ++ "\n") ++ std.fmt.comptimePrint("semantics {x:0>16}\n", .{@import("wire.zig").semantics});
+const version_text = upgrade.version_line ++ "\n" ++ std.fmt.comptimePrint("semantics {x:0>16}\n", .{@import("wire.zig").semantics});
const nested_text =
\\pardes: this shell is already inside pardes, and a pardes inside a pardes
@@ -730,7 +726,7 @@ fn nativeMain(std_init: std.process.Init) !void {
Refuse.with(init.io, word, err);
};
}
- if (wait) waitForDel(init.io, arena, parent.dial, path, made_serial);
+ if (wait) waitForDel(arena, parent.dial, path, made_serial);
return;
}
if (resuming) positional = null;
diff --git a/src/replica.zig b/src/replica.zig
index 990efb9b..16ecc184 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -1215,8 +1215,7 @@ const log = std.log.scoped(.replica);
const nosignal: u32 = if (builtin.os.tag == .linux) libc.MSG.NOSIGNAL else 0;
/// What a client may leave unread, past its join's dump, before it is cut
/// off: minutes of typing, a screenful of a flood's deltas many times over.
-/// PARDES_REPLICA_LAG_KB says another (a test's).
-var lag_max: usize = 64 << 20;
+const lag_max: usize = 64 << 20;
const dump_piece = 1 << 20;
/// A blob in a far join's list (wire.zig `blobs`): its place in the state
/// (u64le), its length (u64le) and its BLAKE3 hash.
@@ -1763,7 +1762,7 @@ pub const Peers = struct {
pub const Note = union(enum) { join: Joining, input: Msg, screen: Msg, gone: *Peer, check: *Peer, joined: *Peer, hashed };
/// A connection to join, and the view it joins again for, if it does.
- pub const Joining = struct { fd: c_int, view: ?u8 = null };
+ pub const Joining = @import("daemon.zig").Joining;
pub const Msg = struct { peer: *Peer, msg: []u8 };
pub fn count(ps: *const Peers) usize {
@@ -2022,7 +2021,6 @@ pub const Peers = struct {
core.gpa.free(bytes);
return refuse(fd, "out of memory");
};
- if (std.c.getenv("PARDES_REPLICA_LAG_KB")) |kb| lag_max = (std.fmt.parseInt(usize, std.mem.span(kb), 10) catch 64 << 10) << 10;
peer.* = .{ .peers = ps, .fd = fd, .id = ps.next_id, .view = k, .limit = lag_max, .dump = bytes, .blobs = blobs, .dump_gpa = core.gpa };
ps.next_id +%= 1;
if (ps.next_id == 0) ps.next_id = 1;