Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file system watching on linux fails to avoid placing marks from different mounts into the same fanotify descriptor #20670

Open
andrewrk opened this issue Jul 18, 2024 · 0 comments · May be fixed by #20672
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. os-linux zig build system std.Build, the build runner, `zig build` subcommand, package management
Milestone

Comments

@andrewrk
Copy link
Member

Follow-up from #20580.

name_to_handle_at gives us a mount ID here:

try posix.name_to_handle_at(path.root_dir.handle.fd, adjusted_path, stack_ptr, &mount_id, std.os.linux.AT.HANDLE_FID);

A given fanotify file descriptor (created by fanotify_init) can only contain marks from the same mount ID. So if we get a different mount ID here, we need to put it into a new fanotify set. The poll later on needs to poll all of them.

Without this fix, we get errors such as

error: unable to watch /nix/store/0c5jp9d9h9818arr6s21xibgjl1ybql0-glibc-2.39-52-dev/include: NotSameFileSystem

Some commonly used Linux distributions will put the Zig standard library into a different mount than the user's home directory, resulting in this problem.

Workaround:

--- a/lib/std/Build/Watch.zig
+++ b/lib/std/Build/Watch.zig
@@ -175,7 +175,7 @@ const Os = switch (builtin.os.tag) {
                                     .ADD = true,
                                     .ONLYDIR = true,
                                 }, fan_mask, path.root_dir.handle.fd, path.subPathOrDot()) catch |err| {
-                                    fatal("unable to watch {}: {s}", .{ path, @errorName(err) });
+                                    std.log.warn("unable to watch {}: {s}", .{ path, @errorName(err) });
                                 };
                             }
                             break :rs dh_gop.value_ptr;

You can apply this workaround without recompiling Zig.

Related:

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. os-linux zig build system std.Build, the build runner, `zig build` subcommand, package management labels Jul 18, 2024
@andrewrk andrewrk added this to the 0.14.0 milestone Jul 18, 2024
@vesim987 vesim987 linked a pull request Jul 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. os-linux zig build system std.Build, the build runner, `zig build` subcommand, package management
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant