#65 Monitoring a directory - different results on different OSes

None
open
nobody
None
5
2013-04-05
2013-04-05
Mikhail Teterin
No

Hello!

I'm trying to use libevent to monitor a set of directories -- and receive events, whenever a new file is created in one of them.

The attached program works on BSD, but does not work on Solaris and Linux. On Solaris I'm simply flooded with events (both read and write are set), whereas on Linux the initialization fails upfront:
[warn] Epoll ADD(-2147483643) on fd 3 failed. Old events were 0; read change was 33 (add); write change was 33 (add): Operation not permitted

On FreeBSD I can run it as:
% ./libevent-test /tmp/
/tmp/ (3) triggered by event(s) 38

After the first event is triggered as above, whenever I create or remove a file in /tmp, or simply ls the directory, there is an event created...

Discussion

  • Test program monitoring directories

     
    Attachments
  • Nick Mathewson
    Nick Mathewson
    2013-04-05

    Epoll doesn't support directories; you'll need to disable it via the event_config mechanism.

    Watching a directory for writes to see when new files are created -- I don't think that's actually portable, is it? You might need to read up on platform-specific behavior to figure out how to implement this correctly, I think.

     
  • Should libevent be automatically trying the next of the possible back-ends under the covers?

    Maybe, this really is a "support request" rather than bug report, but, I thought, if a method works on one OS, but not others, then that in itself is a bug for the library, which seeks to hide the OS-specific idiosyncrasies under a uniform API.

    Monitoring a directory for changes is possible, but the methods are vastly different on different OSes. I was hoping, libevent would hide the OS-specifics...

     
    • Nick Mathewson
      Nick Mathewson
      2013-04-05

      Should libevent be automatically trying the next of the possible back-ends under the covers?

      That's not possible in this case; Libevent need to pick the backend before you start adding events to it, and Libevent has no way in advance to know whether you're going to add non-socket fds unless you tell it.

      I was hoping, libevent would hide the OS-specifics...

      Libevent is focused on hiding OS-specifics, but it doesn't support all possible areas of OS-specifics-hiding right now. Directory monitoring is one thing that it doesn't have support for doing uniformly.

      I would love to have support for this in some future version of Libevent, if anybody can write a patch, though. That's going to require somebody to actually do the research to find out what is the right way to do this on every platform, and then to figure out how to make libevent support it.

       
  • Nick Mathewson
    Nick Mathewson
    2013-04-05

    Ticket moved from /p/levent/bugs/305/