summaryrefslogtreecommitdiff
path: root/src/daemon.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 02:21:02 -0300
committerGabriel Schneider <[email protected]>2026-11-10 03:06:13 -0300
commit22b981446238977d9c3f85eb4856324a9daa9753 (patch)
tree2c3fb711be7e54f6ced04edf605625ed55ce9830 /src/daemon.zig
parent7a443bcdd4d82b259f6a02ade335aa5ccadf2640 (diff)
downloadpardes-22b981446238977d9c3f85eb4856324a9daa9753.tar.gz
pardes-22b981446238977d9c3f85eb4856324a9daa9753.zip
macos: pardes builds for darwin again as far as a Linux host can take it (the tui links, the native shell's libpardes.a and its tests compile; the gui stops at SDL's frameworks and xcrun): recvmsg's CMSG_CLOEXEC and close_range are Linux's (darwin marks the received fds FD_CLOEXEC, closes the rest one by one), hungUp asks no fd of vaxis's test tty there, a kind exports pardes_addon only as its own library's root (macOS's libpardes.a had every compiled-in kind's), and macos.zig drops what the rewrite deleted (animation.zig, the CRT post pass and scene clock, pane transitions and their diff, the presentation's pointer map: the C ABI stays, its lists empty), with its scene, panel-order and panel-mask tests and the theme-fade half of its live-session test gone; the rest of upstream a41360e3 is dropped as superseded (views.zig's RenderMotion and drawOneAt, replica.zig's motion, input stamp, drawAt and animating with its two cursor tests, window_fields and the whitespace hunks)
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.zig13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/daemon.zig b/src/daemon.zig
index 84c77f90..55ffe376 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -102,7 +102,8 @@ fn recv(fd: c_int, buf: []u8) ?Got {
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 };
const n = while (true) {
- const r = libc.recvmsg(fd, &msg, libc.MSG.CMSG_CLOEXEC);
+ // Darwin has no MSG_CMSG_CLOEXEC: its fds are marked below.
+ const r = libc.recvmsg(fd, &msg, if (builtin.os.tag == .linux) libc.MSG.CMSG_CLOEXEC else 0);
if (r >= 0) break r;
if (libc.errno(r) != .INTR) return null;
};
@@ -112,6 +113,9 @@ fn recv(fd: c_int, buf: []u8) ?Got {
if (hdr.level == libc.SOL.SOCKET and hdr.type == libc.SCM.RIGHTS and hdr.len >= data_off) {
got.nfds = @min((hdr.len - data_off) / @sizeOf(c_int), max_fds);
@memcpy(std.mem.sliceAsBytes(got.fds[0..got.nfds]), cbuf[data_off..][0 .. got.nfds * @sizeOf(c_int)]);
+ if (builtin.os.tag != .linux) for (got.fds[0..got.nfds]) |f| {
+ _ = libc.fcntl(f, libc.F.SETFD, @as(c_int, 1)); // FD_CLOEXEC
+ };
}
}
// A zero-length datagram is never sent: it is the peer's end.
@@ -248,8 +252,11 @@ fn spawn(listener: c_int, lock: c_int) bool {
const l = libc.fcntl(listener, libc.F.DUPFD, @as(c_int, 10));
const k = libc.fcntl(lock, libc.F.DUPFD, @as(c_int, 10));
if (l < 0 or k < 0 or libc.dup2(l, 3) < 0 or libc.dup2(k, 4) < 0) libc._exit(127);
- // Linux's by its syscall: musl (a static pardes) has no close_range.
- const shut = if (comptime builtin.os.tag == .linux) std.os.linux.close_range(5, std.math.maxInt(i32), .{ .UNSHARE = false, .CLOEXEC = false }) == 0 else close_range(5, std.math.maxInt(c_uint), 0) == 0;
+ // Linux's by its syscall: musl (a static pardes) has no close_range;
+ // nor has Darwin, which closes them one by one.
+ const shut = if (comptime builtin.os.tag == .linux)
+ std.os.linux.close_range(5, std.math.maxInt(i32), .{ .UNSHARE = false, .CLOEXEC = false }) == 0
+ else if (comptime builtin.os.tag.isDarwin()) false else close_range(5, std.math.maxInt(c_uint), 0) == 0;
if (!shut) {
var fd: c_int = 5;
while (fd < 1024) : (fd += 1) _ = libc.close(fd);