I want to monitor a single directory using fanotify, but what I got is monitoring the whole filesystem. This is the code:
fa_fd = fanotify_init(FAN_CLOEXEC | FAN_CLASS_CONTENT, O_RDONLY | O_LARGEFILE | O_CLOEXEC);
static uint64_t event_mask =
(FAN_ACCESS | /* File accessed */
FAN_MODIFY | /* File modified */
FAN_CLOSE_WRITE | /* Writable file closed */
FAN_OPEN | /* File was opened */
FAN_EVENT_ON_CHILD); /* We want to be reported of events in files of the directory */
filesystem::path path("some-relative-path");
if (!filesystem::exists(path)){
filesystem::create_directory(path);
}
if (fanotify_mark(fa_fd,
FAN_MARK_ADD,
event_mask,
AT_FDCWD,
"some-relative-path") >= 0)
{
return NO_ERROR;
}
I have read from fanotify's man page if pathname("some-relative-path") is relative and we have set fds to AT_FDCWD then we are asking for mark that relative path.
I'm working with threads but I don't think that's the problem. Maybe I'm using wrong some flag or I'm not using the correct one at all.