inotify not firing notifications on file modification

百般思念 提交于 2019-12-04 05:55:15

After themel's fix, your code works fine when watching a directory, in my tests. When watching a file, event->len is zero, and your code ignores the notifications.

With the test for event->len removed and all event->name replaced by file_path in the printf statements, it works fine when watching a file as well.

PS: Just noticed you mention touch.

touch sends the following events:

IN_OPEN
IN_ATTRIB
IN_CLOSE_WRITE

no IN_MODIFY

Also, don't test modification by editing it with vim as I just did - it deletes the file while shuffling the working copy and the swap, which removes the watch. pico works.

Your handling of i is broken, you never reset it to 0 in the loop. This causes any later inotify events to be considered only when they are longer than the longest event before them, which is not likely what you want.

Fixed version.

when monitoring an individual file event->len will be 0 because the file name is not returned. I noticed a lot of the example programs have this issue.

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