Linux iNotify 一次性和事件掩码问题
我正在尝试在 Linux rhel5、内核 2.6.18、glibc 2.5-18 中使用 iNotify。 我并没有将这个事件定义为一次性的,但由于某种原因,它的表现就像我所做的那样。 影响是我必须在每次事件后重新添加手表。 有人用过 iNotify 吗? 另一个问题是事件对象中返回的掩码仅包含一个标志:IN_ONE_SHOT。
I'm trying to use iNotify in linux rhel5, kernel 2.6.18, glibc 2.5-18. I did not define the event as one shot but for some some reason it behaves as if I did. The impact is that I have to re-add a watch after each event. Any one ever used iNotify? Another problem is that the mask returned in the event object contains only one flag: IN_ONE_SHOT.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编写尽可能小的示例并进行测试。 如果它展示了您正在谈论的行为,请将其添加到您的问题中。 如果它表现正常,则添加更多代码并再次测试。 不断重复,直到重现错误或代码正常运行。 我经常发现构建一个玩具程序可以准确地告诉我我做错了什么,而这是我在较大的程序中看不到的。
Write the smallest example you can and test that. If it demonstrates the behaviour you are talking about then add it to your question. If it behaves normally then add a little more of your code and test again. Keep repeating until you have reproduced the error or you have your code working. Often I find that building a toy program tells me exactly what I am doing wrong that I could not see in a larger program.
inotify 可能会隐式删除监视,因为文件正在被删除。 手册页巧妙地引用了该行为(请参阅有关 IN_IGNORED 事件的部分)。 您可以通过检查调用
read
填充的 inotify_event 中是否设置了标志 IN_IGNORED 来检查是否发生了这种情况。另请参阅修改和保存文件时inotify delete_self 为什么在您认为只是修改期间,文件可能会在您不知情或不采取行动的情况下被删除。
It is probable that inotify is implicitly deleting the watch because the file is being deleted. The behaviour is subtly referred to by the manual page (see the section on the IN_IGNORED event). You can check if this is happening by checking if the flag IN_IGNORED is set in the inotify_event populated by your call to
read
.See also inotify delete_self when modifying and saving a file for why the file may be deleted without your knowledge or action during what you think is just a modification.