diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-29 12:32:23 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-29 13:11:16 -0300 |
| commit | 6b89fed454fd56a3af4b576646538b45d3315146 (patch) | |
| tree | f4be48c98368bc8c85c461af97528743afc98f59 /src/file_watch.zig | |
| parent | 34551a64366b3257ac577c5b68288f955c9eea80 (diff) | |
| download | pardes-6b89fed454fd56a3af4b576646538b45d3315146.tar.gz pardes-6b89fed454fd56a3af4b576646538b45d3315146.zip | |
FreeBSD: the tty pardes builds for it and runs there, terminals, 9P and the daemon included
Cross-compiled with -Dtarget=x86_64-freebsd.15.0 (15 ships libutil.so.10;
Zig's default 14.0 links .so.9) and run on the FreeBSD 15.1 box:
- 9p_io serves there: fstatat, not Linux's statx. madvise is Linux's.
- WINCH reaches the sigwait thread through a handler that does nothing:
FreeBSD drops a signal ignored by default as it is sent.
- A dead terminal answers a write with ENXIO, which std does not expect: a
Debug build traced it to stderr, that same terminal, and recursed until
the stack ran out (a session whose ssh dropped hung). No tracing there.
- waitid's FreeBSD numbers and 64-bit id: a command pane's exit is seen.
- No /proc: a shell's directory and program by sysctl, ttyTaken by the
foreground group, the foreground job's name by its program.
- File watching by FreeBSD 15's inotify.
- ghostty's kitty loader: off Linux a stat comes before a t=f open (a FIFO
hung it); FreeBSD's shm_open refuses O_NONBLOCK.
- vaxis's test terminal has no read off Linux: no input thread for it.
- test-install: the test-build programs installed into <prefix>/test, to
run where the build cannot.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/file_watch.zig')
| -rw-r--r-- | src/file_watch.zig | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/file_watch.zig b/src/file_watch.zig index e3fe9963..9b41d146 100644 --- a/src/file_watch.zig +++ b/src/file_watch.zig @@ -5,9 +5,10 @@ //! is their generation. Large PDFs use metadata which changes for in-place and //! rename-over saves, avoiding a second whole-document allocation. //! -//! Two kernels, one transaction: inotify on linux, kqueue on macos. `init`, -//! `wait`, `stop`, `drain`, `markDir` and `unmarkDir` are the whole of that -//! difference, and nothing above them knows which one it is on. +//! Two kernels, one transaction: inotify on linux (and FreeBSD 15's, the +//! same events), kqueue on macos. `init`, `wait`, `stop`, `drain`, `markDir` +//! and `unmarkDir` are the whole of that difference, and nothing above them +//! knows which one it is on. const std = @import("std"); const builtin = @import("builtin"); const libc = std.c; @@ -81,7 +82,7 @@ pub const Table = [shader_slot + pardes.config.Runtime.Post.max]?Watch; /// empty and `reloadPane` returns false for every slot. The core then keeps its /// own record of what was asked and simply never gets a `file_changed`, which /// is what a host with no watcher has always done here. -pub const supported = builtin.os.tag == .linux or builtin.os.tag == .macos; +pub const supported = builtin.os.tag == .linux or builtin.os.tag == .freebsd or builtin.os.tag == .macos; /// The wake filter's `ident` on macos. `ident` is a directory descriptor for /// every other filter on this queue, and no descriptor is `maxInt(usize)`, so @@ -113,6 +114,8 @@ pub fn init(polled: bool) c_int { linux.IN.CLOEXEC | linux.IN.NONBLOCK else linux.IN.CLOEXEC), + // FreeBSD's IN_CLOEXEC and IN_NONBLOCK are its O_ flags. + .freebsd => return libc.inotify_init1(if (polled) 0x00100000 | 0x4 else 0x00100000), .macos => { const kq = libc.kqueue(); if (kq < 0) return -1; @@ -193,7 +196,7 @@ pub fn stop(fd: c_int) void { pub fn drain(fd: c_int) bool { if (fd < 0) return false; switch (builtin.os.tag) { - .linux => { + .linux, .freebsd => { var buf: [4096]u8 = undefined; var seen = false; while (libc.read(fd, &buf, buf.len) > 0) seen = true; @@ -227,7 +230,7 @@ pub fn drain(fd: c_int) bool { /// and inode, because each EVFILT_VNODE filter needs a descriptor of its own. fn markDir(fd: c_int, dir_z: [:0]const u8, watches: *const Table) c_int { switch (builtin.os.tag) { - .linux => { + .linux, .freebsd => { // CLOSE_WRITE coalesces one writer's writes; MOVED_TO and CREATE // cover rename-over and delete-then-recreate saves; DELETE and // MOVED_FROM a file going away, said at once (File.deleted), not @@ -366,7 +369,7 @@ fn unmark(fd: c_int, old: Watch, drop_dir: bool) void { } if (!drop_dir) return; switch (builtin.os.tag) { - .linux => _ = libc.inotify_rm_watch(fd, old.wd), + .linux, .freebsd => _ = libc.inotify_rm_watch(fd, old.wd), .macos => _ = libc.close(old.wd), else => {}, } |
