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.
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.
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.
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.