inotify不触发文件修改的通知 [英] inotify not firing notifications on file modification

查看:390
本文介绍了inotify不触发文件修改的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在调整这里使其重复观看文件以进行修改。我的代码是此处。在我的测试中,inotify通知仅在第一次修改文件时触发(即 touch 'ed)。对文件的任何后续修改不会导致任何通知。 stat 显示修改时间已更改。此外,修改代码以删除手表并在每次触发通知时重新添加(即移动 inotify_add_watch inotify_rm_watch 放在我的示例中的 while(1)循环中)没有帮助解决这个问题。

I have been tweaking the example here to make it repeatedly watch a file for 'modifications'. My code is here. In my tests the inotify notification is only firing the first time the file is 'modified'(i.e. touch'ed). Any subsequent modifications to the file are not causing any notifications to fire. stat shows that the 'Modify' time has changed. Also, modifying the code to remove the watch and re-add each time a notification fires(i.e. move inotify_add_watch and inotify_rm_watch to be inside the while(1) loop in my sample) did not help resolve this issue.

我在想,如果有人在这里可以帮助我可能会做错了。此外,虽然我添加了一个手表 IN_ALL_EVENTS ,我真的只关心 IN_MODIFY 事件。不知道这是否有什么区别。

I was wondering if any one here could help with what I may be doing wrong. Also, although I have added a watch for IN_ALL_EVENTS, I really only care about IN_MODIFY events. Not sure if that makes any difference.

此外,这个用例不工作吗?我应该改变我的方法来观看目录吗?请指导。

Also, does this use case not work? Should I change my approach to watch the directory instead? Please advice.

TIA。

编辑1:如样式 i 的处理需要一些修复。然而,即使固定版本不会为后续文件系统的事件触发通知。此外,在目录而不是文件中添加一个手表表现出类似的非确定性行为。

Edit 1: As noted by themel, the handling of i needed some fixing. However even the fixed version is not firing notifications for subsequent filesystem 'events'. Also, adding a watch on the directory as opposed to the file is exhibiting similar non-deterministic behavior.

编辑2:我想得到这个 asio + inotify示例,基于此答案工作。不幸的是,这个例子一直没有为我工作。任何帮助将不胜感激。 TIA。

Edit 2: I would like to get this asio + inotify example based on this answer to work. Unfortunately that example hasn't been working for me at all. Any help would be much appreciated. TIA.

推荐答案

在我的测试中,在看到目录后,你的代码可以正常工作。当观看文件时, event-> len 为零,您的代码将忽略通知。

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.

测试 event-> len 已删除,所有 event-> name 替换为 file_path

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:只是注意到你提到了 touch

PS: Just noticed you mention touch.

触摸会发送以下事件:

IN_OPEN
IN_ATTRIB
IN_CLOSE_WRITE


b $ b

否IN_MODIFY

no IN_MODIFY

此外,不要通过使用 vim 只是 - 它删除文件,当洗牌工作副本和交换,这会删除手表。 pico 工程。

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.

这篇关于inotify不触发文件修改的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆