[Unison-hackers] inotify

Mitch Skinner lists at arctur.us
Sun Oct 1 14:15:30 EDT 2006


Hello,

I've started working on inotify support.

For those not familiar with inotify, it's a Linux feature that allows
programs to watch directories for changes.  Similar functionality exists
on other platforms; on windows there's ReadDirChangesW, on BSD
apparently you can use kqueues, I'm sure there's something on OS X but I
don't know what it is.  So far what I have is linux-specific; if people
want to do the work for other platforms then maybe we could design some
kind of generic interface, but that sounds like a lot of work so for the
first iteration I'd like to just focus on the platform I have handy.

So far, all I've got is a bare-bones O'Caml wrapper for the inotify C
interface.  That appears to be working well, but now I'm trying to
figure out how to integrate it with unison, and I have to admit I'm a
bit stumped.

As I see it, two main changes need to be made:
1. The code that walks the directories needs to register the directories
of interest for watching.  I believe this needs to happen before update
detection, to avoid missing changes.  My current best guess is that this
belongs somewhere in update.ml (findLocal? buildUpdate*?).
2. There needs to be some kind of driver that processes the change
notifications from inotify.  Inotify messages come from the kernel via a
file descriptor; you select() on it or do a blocking read.  I think
there's a way to specify a file descriptor for the GTK mainloop to
monitor but I don't know the details.  Alternatively, maybe we could
have a separate thread do blocking reads and make the results available
through some kind of queue?  I'm an O'Caml newbie, so I'd love some
advice there.

#2 is really the meat of the whole thing.  I'm willing to put in the
elbow grease to see it through (to whatever standards y'all want), but
I'd like to get some advice on how to approach it.  Should it sync
changes periodically, or as they happen?  How should the UI work?

I've put up my inotify O'Caml wrapper here, in case anyone is curious
about the details of how inotify works:
http://arctur.us/unison/

I've pasted in a transcript below showing how the inotify test program
works.  Ctrl-C exits.

Thanks for any advice, I'm a newbie to almost all of this,
Mitch

[mitch at firebolt inotify_caml]$ ls
compile         inotify.h   inotify.mli         inotify_test.ml
inotify_caml.c  inotify.ml  inotify-syscalls.h
[mitch at firebolt inotify_caml]$ . compile
In file included from inotify_caml.c:5:
inotify-syscalls.h: In function ‘inotify_init’:
inotify-syscalls.h:48: warning: implicit declaration of function ‘syscall’
[mitch at firebolt inotify_caml]$ mkdir testdir
[mitch at firebolt inotify_caml]$ sleep 10 && touch testdir/foo &
[1] 20884
[mitch at firebolt inotify_caml]$ ./inotify_test testdir/
**Events received** (32 bytes)
Event:
  Watch descriptor: 1
  Mask: IN_CREATE
  Cookie: 0
  Name: foo

**Events received** (32 bytes)
Event:
  Watch descriptor: 1
  Mask: IN_OPEN
  Cookie: 0
  Name: foo

**Events received** (32 bytes)
Event:
  Watch descriptor: 1
  Mask: IN_CLOSE_WRITE, IN_CLOSE
  Cookie: 0
  Name: foo

**Events received** (32 bytes)
Event:
  Watch descriptor: 1
  Mask: IN_ATTRIB
  Cookie: 0
  Name: foo


[1]+  Done                    sleep 10 && touch testdir/foo
[mitch at firebolt inotify_caml]$




More information about the Unison-hackers mailing list