Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Question

inotify_rm_watch returns EINVAL on legitimate call

Jul 30, 2011 1:06AM PDT

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 ? Thanks

Discussion is locked

- Collapse -
Clarification Request
What kernel are you running?
Jul 30, 2011 5:17PM PDT

What kernel are you running?

- Collapse -
Answer
A long time ago and a similar issue.
Jul 30, 2011 8:37AM PDT

I had to cure it the hard way. What I did was to write my app in 2 pieces. A watcher that would launch the app and the watcher would relaunch the app if the app signal back it had failed. You may have to recycle this old method if you can't fix your app.
Bob