summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-31 09:02:18 -0300
committerGabriel Schneider <[email protected]>2026-10-31 09:02:18 -0300
commit6d3b6cbc1361d174ffabb49b2ee84c5c6039dda5 (patch)
tree0809839cacd93451df22563271d0c07fd2bafdbd
parenta479792a1ab2b593642d7f648194bfa23ce01dba (diff)
downloadpardes-6d3b6cbc1361d174ffabb49b2ee84c5c6039dda5.tar.gz
pardes-6d3b6cbc1361d174ffabb49b2ee84c5c6039dda5.zip
Enable native macOS replica sockets and repair platform validation
-rw-r--r--src/builtins.zig5
-rw-r--r--src/daemon.zig1
-rw-r--r--src/macos.zig2
-rw-r--r--src/pardes.zig17
-rw-r--r--src/replica.zig34
5 files changed, 38 insertions, 21 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index 38a4d835..f59d30fe 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -118,7 +118,6 @@ fn isEnabled(comptime T: type) bool {
return !@hasDecl(T, "enabled") or T.enabled;
}
-
/// Why `word`, a builtin some build has, is none in this one: `GUI-only`
/// for the GUI's own (`gui_only`), else `not in this build`; null for a
/// word that is one here, or in no build.
@@ -498,6 +497,10 @@ test "Ligatures is a setting only in the shell that shapes text" {
defer p.deinit();
// A desktop build has the word, which a window's view takes alone.
try std.testing.expectEqual(desktop, @hasField(registry.Builtin(), "Ligatures"));
+ if (comptime !desktop) {
+ try std.testing.expect(!p.executeBuiltinLine(p.active, "Ligatures off"));
+ return;
+ }
const exists = registry.here(p, .Ligatures);
try std.testing.expectEqual(pardes.platform == .gui, exists);
// Taken either way: run, or said to be GUI-only.
diff --git a/src/daemon.zig b/src/daemon.zig
index b93f5d43..fc043157 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -97,6 +97,7 @@ pub const Got = struct { words: []const u8, fds: [max_fds]c_int = undefined, nfd
/// The next message, its fds close-on-exec; null at the end of the link.
pub fn recv(fd: c_int, buf: []u8) ?Got {
+ if (comptime !supported) return null;
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 };
diff --git a/src/macos.zig b/src/macos.zig
index 76e4ba19..a63ac626 100644
--- a/src/macos.zig
+++ b/src/macos.zig
@@ -1248,7 +1248,7 @@ test "mac Restore keeps host state and rejects callbacks from the old core" {
core.update(.{ .command = try std.fmt.bufPrint(&command, "Restore .zig-cache/tmp/{s}/restore.zon", .{tmp.sub_path}) });
try std.testing.expect(restoreCore(&st));
try std.testing.expect(st.core != core);
- try std.testing.expect(st.core.panes[0].?.serial > old_serial);
+ try std.testing.expectEqual(old_serial, st.core.panes[0].?.serial);
try std.testing.expectEqualStrings("saved body\n", st.core.panes[0].?.file.?.content);
try std.testing.expectEqualStrings("host configuration", marker);
try std.testing.expectEqual(@as(usize, 0), st.frame_len);
diff --git a/src/pardes.zig b/src/pardes.zig
index edab4a58..e14e9273 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -2872,7 +2872,7 @@ test "Pet command is SDL-only optional and validates its argument" {
try std.testing.expectEqual(.off, p.settings.pet);
if (comptime platform != .gui) {
// A terminal's view has the word and takes it not.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Pet cat"));
+ try std.testing.expectEqual(@hasField(Builtin, "Pet"), p.executeBuiltinLine(p.active, "Pet cat"));
try std.testing.expectEqual(.off, p.settings.pet);
return;
}
@@ -4762,19 +4762,20 @@ pub const Pardes = struct {
pub const replica = .{
.local = .{
// A frame, and the animations and timings that make it.
- "surface", "presentation", "frames", "chrome_animation", "lifts", "lift_serials",
- "cursor_glide", "cursor_view", "cursor_crossing", "cursor_held", "frame_arena", "scratch",
- "needs_frame", "present_skipped", "shell_continuous", "native_image_patches",
- "echo",
+ "surface", "presentation", "frames", "chrome_animation", "lifts", "lift_serials",
+ "cursor_glide", "cursor_view", "cursor_crossing", "cursor_held", "frame_arena", "scratch",
+ "needs_frame", "present_skipped", "shell_continuous", "native_image_patches", "echo",
// Drained by every pump before its digest; a replica's queues
// are its own.
- "effects", "effects_head", "effects_len", "in_q", "in_head", "in_len",
+ "effects",
+ "effects_head", "effects_len", "in_q", "in_head", "in_len",
// The views not live: written whenever one goes out, so the
// live one's slot is stale (views.zig).
- "parked", "undrawn",
+ "parked",
+ "undrawn",
// How this process was started, and the last dump it made for
// its host to write: a session loaded elsewhere has its own.
- "opts", "dump_out",
+ "opts", "dump_out",
},
.derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome" },
// The host's handles, the 9P server's fids and log, the store file
diff --git a/src/replica.zig b/src/replica.zig
index 8cacb075..155492c3 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -1210,6 +1210,15 @@ fn terminalDigests(p: *const Pardes, out: *[pardes.MAX_PANES]u64) void {
const libc = std.c;
const log = std.log.scoped(.replica);
const nosignal: u32 = if (builtin.os.tag == .linux) libc.MSG.NOSIGNAL else 0;
+const stream_kind = libc.SOCK.STREAM | (if (builtin.os.tag.isDarwin()) 0 else libc.SOCK.CLOEXEC);
+
+fn prepareStream(fd: c_int) void {
+ @import("9p_io.zig").setCloexec(fd);
+ if (comptime builtin.os.tag.isDarwin()) {
+ const on: c_int = 1;
+ _ = libc.setsockopt(fd, libc.SOL.SOCKET, libc.SO.NOSIGPIPE, &on, @sizeOf(c_int));
+ }
+}
/// 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).
@@ -2211,9 +2220,9 @@ pub const Peers = struct {
fn writeStats(ps: *Peers, path: []const u8) void {
var buf: [400]u8 = undefined;
const line = std.fmt.bufPrint(&buf, "session inputs {d} input_us {d}/{d}/{d} boundaries {d} boundary_us {d}/{d}/{d} join_us {d} dump_kb {d} state_kb {d} cut {d}\n", .{
- ps.input_ns.items.len, pctOf(ps.input_ns.items, 50) / 1000, pctOf(ps.input_ns.items, 99) / 1000, pctOf(ps.input_ns.items, 100) / 1000,
- ps.boundary_ns.items.len, pctOf(ps.boundary_ns.items, 50) / 1000, pctOf(ps.boundary_ns.items, 99) / 1000, pctOf(ps.boundary_ns.items, 100) / 1000,
- ps.join_ns / 1000, ps.dump_bytes >> 10, ps.state_bytes >> 10, ps.cut,
+ ps.input_ns.items.len, pctOf(ps.input_ns.items, 50) / 1000, pctOf(ps.input_ns.items, 99) / 1000, pctOf(ps.input_ns.items, 100) / 1000,
+ ps.boundary_ns.items.len, pctOf(ps.boundary_ns.items, 50) / 1000, pctOf(ps.boundary_ns.items, 99) / 1000, pctOf(ps.boundary_ns.items, 100) / 1000,
+ ps.join_ns / 1000, ps.dump_bytes >> 10, ps.state_bytes >> 10, ps.cut,
}) catch return;
var z: [4096]u8 = undefined;
const pz = std.fmt.bufPrintSentinel(&z, "{s}", .{path}, 0) catch return;
@@ -2265,8 +2274,9 @@ pub const Got = struct { pos: usize, len: usize, hash: [32]u8 };
/// for those it holds nowhere. Errors are said in `why`. `view`: the one
/// it had, joining again for it.
pub fn dial(gpa: Allocator, path: []const u8, session: []const u8, why: []u8, have: ?*Have, view: ?u8) ?Joined {
- const fd = libc.socket(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0);
+ const fd = libc.socket(libc.AF.UNIX, stream_kind, 0);
if (fd < 0) return said(why, "no socket", .{});
+ prepareStream(fd);
var addr: libc.sockaddr.un = .{ .path = @splat(0) };
if (path.len >= addr.path.len) {
_ = libc.close(fd);
@@ -2972,11 +2982,11 @@ pub const Link = struct {
const e = &c.r.echo.stats;
var w: std.Io.Writer = .fixed(&buf);
w.print("inputs {d} at_once {d} stopped {d} units {d} fast {d} neutral {d} mispredicted {d} foreign {d} visible {d} rtt_us {d} spec_us {d}/{d} copy_us {d}/{d} rollback_us {d}/{d} join_ms {d} blobs {d} from_memory {d} from_disk {d} sent_kb {d} echo {d}/{d} confirmed {d} missed {d}", .{
- st.inputs, st.speculated, st.stopped, st.units, st.fast,
- c.r.neutral, st.mispredicted, st.foreign, c.visible, c.r.rtt_ns / 1000,
- pctOf(st.spec_ns.items, 50) / 1000, pctOf(st.spec_ns.items, 99) / 1000, pctOf(st.copy_ns.items, 50) / 1000, pctOf(st.copy_ns.items, 99) / 1000, pctOf(st.rollback_ns.items, 50) / 1000,
- pctOf(st.rollback_ns.items, 99) / 1000, c.join_ms, c.join.blobs, c.join.from_memory, c.join.from_disk,
- c.join.sent_bytes >> 10, e.predicted, e.predicted + e.unpredicted, e.confirmed, e.mispredicted,
+ st.inputs, st.speculated, st.stopped, st.units, st.fast,
+ c.r.neutral, st.mispredicted, st.foreign, c.visible, c.r.rtt_ns / 1000,
+ pctOf(st.spec_ns.items, 50) / 1000, pctOf(st.spec_ns.items, 99) / 1000, pctOf(st.copy_ns.items, 50) / 1000, pctOf(st.copy_ns.items, 99) / 1000, pctOf(st.rollback_ns.items, 50) / 1000,
+ pctOf(st.rollback_ns.items, 99) / 1000, c.join_ms, c.join.blobs, c.join.from_memory, c.join.from_disk,
+ c.join.sent_bytes >> 10, e.predicted, e.predicted + e.unpredicted, e.confirmed, e.mispredicted,
}) catch return;
// What stopped its inputs, last: a word a pair before it.
w.writeAll(" stops ") catch return;
@@ -3507,7 +3517,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves
// Normal mode in the shell, up a few rows, then half a screen and more:
// the cursor leaves the view, and the view follows it back.
const keys = [_]pardes.Key{
- .{ .cp = a.core.opts.tty_toggle, .ctrl = true }, .{ .cp = 'k', .text = "k" }, .{ .cp = 'k', .text = "k" },
+ .{ .cp = a.core.opts.tty_toggle, .ctrl = true }, .{ .cp = 'k', .text = "k" }, .{ .cp = 'k', .text = "k" },
.{ .cp = 'u', .ctrl = true }, .{ .cp = 'u', .ctrl = true }, .{ .cp = 'k', .text = "k" },
};
for (keys) |k| try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .key = k })));
@@ -3789,7 +3799,9 @@ test "the blob cache stays under its cap, the least recently used going first" {
/// its hello read off first.
fn farJoinOnce(ps: *Peers, core: *Pardes, have: ?*Have) !Joined {
var fds: [2]c_int = undefined;
- if (libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &fds) != 0) return error.NoSocket;
+ if (libc.socketpair(libc.AF.UNIX, stream_kind, 0, &fds) != 0) return error.NoSocket;
+ prepareStream(fds[0]);
+ prepareStream(fds[1]);
var blobs: std.ArrayListUnmanaged(walk.Deferred) = .empty;
const state = pardes.dump.dumpJoin(core, &blobs) catch |err| {
_ = libc.close(fds[0]);