Commit 2ebf021061

Andrew Kelley <andrew@ziglang.org>
2024-07-10 08:34:08
build runner: don't pass a dirfd + null to fanotify_mark
Otherwise it reports EBADF.
1 parent 7bccef3
Changed files (2)
lib
compiler
std
Build
Cache
lib/compiler/build_runner.zig
@@ -419,7 +419,7 @@ pub fn main() !void {
                         std.posix.fanotify_mark(w.fan_fd, .{
                             .ADD = true,
                             .ONLYDIR = true,
-                        }, Watch.fan_mask, path.root_dir.handle.fd, path.subPathOpt()) catch |err| {
+                        }, Watch.fan_mask, path.root_dir.handle.fd, path.subPathOrDot()) catch |err| {
                             fatal("unable to watch {}: {s}", .{ path, @errorName(err) });
                         };
 
@@ -471,7 +471,7 @@ pub fn main() !void {
                 try std.posix.fanotify_mark(w.fan_fd, .{
                     .REMOVE = true,
                     .ONLYDIR = true,
-                }, Watch.fan_mask, path.root_dir.handle.fd, path.subPathOpt());
+                }, Watch.fan_mask, path.root_dir.handle.fd, path.subPathOrDot());
 
                 w.dir_table.swapRemoveAt(i);
                 w.handle_table.swapRemoveAt(i);
lib/std/Build/Cache/Path.zig
@@ -173,6 +173,10 @@ pub fn subPathOpt(self: Path) ?[]const u8 {
     return if (self.sub_path.len == 0) null else self.sub_path;
 }
 
+pub fn subPathOrDot(self: Path) []const u8 {
+    return if (self.sub_path.len == 0) "." else self.sub_path;
+}
+
 /// Useful to make `Path` a key in `std.ArrayHashMap`.
 pub const TableAdapter = struct {
     pub const Hash = std.hash.Wyhash;