fanotify: What I'm doing wrong?

北城以北 提交于 2019-12-13 05:50:40

问题


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.


回答1:


I have face this problem, when we use FAN_EVENT_ON_CHILD, fanotify monitors the entire mount point of that specified directory/file. When you monitor only directory, with FAN_ONDIR, fanotify monitors only files in that directory and not sub-directories.

Therefore, you have to monitor either whole mount point or a directory without its sub-directories. Notice that, you can skip some files/directories while monitoring entire mount point(s). I hope this will help you :)



来源:https://stackoverflow.com/questions/19909063/fanotify-what-im-doing-wrong

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!