ev_stat inotify implementation might miss events

Yoann Vandoorselaere yoann.v at prelude-ids.com
Tue Jan 26 09:40:19 CET 2010


Le lundi 25 janvier 2010 à 21:44 +0100, Marc Lehmann a écrit :
> On Mon, Jan 25, 2010 at 08:46:37PM +0100, Yoann Vandoorselaere <yoann.v at prelude-ids.com> wrote:
> > Every write will trigger a libev events *if* the libev specified
> > callback function return sufficiently fast. 
> 
> Yes, and if it's too slow, this will not happen. If you rely on getting an
> event for *every* change, then your code is broken - libev doesn't guarantee
> that (and it's impossible in fact).

As I understand it, inotify guarantee that you'll get an event for every
changes on the file. However, it might happen that Inotify merge event
together, if the same event is received multiple time.

However, my earlier interpretation of the problem was incorrect. I took
more time to read the code more deeply, and here is what seems to
happen:

- libev monitor a file
- inotify detect multiples changes to this file
 - infy_cb() called, loop through the changes
   - infy_wd() called, find the right ev_stat structure
    - stat_timer_cb is called
     - infy_del() is called
     - infy_add() is called
     - feed_event is called

The problem is that the call to infy_del(), followed by infy_add() will
reallocate the inotify watch descriptor (wd) used to identify the
monitored file.

This is not a problem if there is no more event queued for the given wd;
but in the other case, if there are multiple events queued, then the
infy_cb loop is going to continue calling infy_wd() with the *old* watch
descriptor. 

Then, infy_wd() won't be able to find the corresponding ev_stat
structure since the watch descriptor used by Inotify has been
reallocated in libev. This lead to some events being lost.


> libev needs to rearm inotify after a change, as the event might have
> changed the path.

Are you talking about file renaming/deletion? If you are, I might have
some suggestion on other way to handle that. 

-- 
Yoann Vandoorselaere | Directeur Technique/CTO | PreludeIDS Technologies
Tel: +33 (0)1 40 24 65 10                      Fax: +33 (0)1 40 24 65 28
http://www.prelude-ids.com




More information about the libev mailing list