inotify_rm_watch returns EINVAL on legitimate call
I am working on software that is to run on a variety of different linux machines where changing the os/version is not an option.
My software uses the inotify_rm_watch call, and this is occasionally failing.
In every case the operands are both valid, yet the result is EINVAL.
This appears to only occur when a watched file is deleted, AND the read command on the inotify yields two events IN_DELETE_SELF AND IN_IGNORE (at the same time).
On occasion, my software works fine, on other occasions, the inotify_rm_watch fails, and after the file is re-created, I get no further events on that file and I can not re-add it to the inotify_watch.
People have said I do not need to use inotify_rm_watch when the file is deleted .. it is done automatically. The results I have seen are NOT consistent AND in the end it just does not work. To be clearer, the inotify_rm_watch call fails about 20% after the watched file is deleted.
I have seen a few messages detailing this same scenario - but no workarounds. Any suggestions ?
This happens on a few machines, including one with kernel 2.6.27.