Ticket #95 (closed enhancement: fixed)

Opened 5 years ago

Last modified 5 years ago

inotify support for adding/updating/removing services

Reported by: behanw Owned by: lennart
Milestone: Avahi 0.6.18 Component: avahi-daemon
Keywords: Cc:

Description

Here is a patch which adds an inotify watch to the avahi services directory. As services are added, updated or deleted, the avahi-daemon automatically does the right thing without user intervention.

This is kind of like Ticket #33, except unlike fam or gamin, inotify does understand when a file is closed, added, or deleted.

Attachments

avahi-daemon-inotify.diff (9.5 kB) - added by behanw 5 years ago.
Add inotify support to avahi-daemon for the services directory

Change History

Changed 5 years ago by behanw

Add inotify support to avahi-daemon for the services directory

Changed 5 years ago by lennart

  • status changed from new to assigned

Thanks for the patch!

I haven't checked the patch thoroughly, but from a first quick look I got the impression that there is a race condition between an app writing a file to /etc/avahi/services/ and avahi reading it immediately when the file appears but is not completely written yet.

Did I get that wrong?

In addition, if one writes a large file to that directory, won't avahi wake up many times and try to read the the file over and over?

Changed 5 years ago by behanw

No, no race condition.

I've instructed inotify to watch for the file to closed, moved to/from the directory, or deleted. All these things happen once writing to the file is complete.

Same for a large file. It only gets told once the file handle is closed.

I hope this helps!

Changed 5 years ago by behanw

Incidentally, thanks for avahi! :)

Changed 5 years ago by behanw

I should also mention that inotify support was added to the linux kernel in 2.6.13. Using this patch with a kernel older than that will be problematic.

I haven't added --without-inotify to configure.ac, although I suspect that might be a good idea.

Another idea I was thinking about for the future was to only load each file as it is updated instead of trying to reload everything (as if a -HUP was received) which is what I've currently done.

I was trying to keep this patch as simple as possible for now before proposing further changes.

Changed 5 years ago by lennart

I like the patch, however, before I will merge it a few things need to fixed:

Avahi has been ported to a few non-Linux systems and should work on pre-2.6.13 as well. Hence, please add some code enable inotify only if the macro linux is defined. And also, please add code so that inotify is disabled cleanly (wihout terminating avahi-daemon) if inotify_init() fails. Also, please show a clean error message (i.e. strerror()) if inotify_xxx() or read() fails.

Otherwise the patch looks fine to me!

Changed 5 years ago by lennart

bah, trac interpreted my underscores around the "linux" macro as formatting command. It should read like this:

Hence, please add some code enable inotify only if the macro __linux__ is defined

Changed 5 years ago by lennart

  • milestone set to Avahi 0.6.18

Changed 5 years ago by lennart

  • status changed from assigned to closed
  • resolution set to fixed

(In [1426]) Add inotify support for /ect/avahi/services and /etc/avahi/hosts. Based on a patch from "behanw". (Closes #95, #33)

Note: See TracTickets for help on using tickets.