This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nscd/14906] inotify failed when /etc/hosts file change


http://sourceware.org/bugzilla/show_bug.cgi?id=14906

--- Comment #2 from Bin Li <binli at opensuse dot org> 2012-12-03 10:40:11 UTC ---
Miklos Szeredi 2012-10-15 15:27:29 UTC

(In reply to comment #20)
> I can make the program work as expected also in the light of overwriting
> renames, when I'm handling a IN_IGNORED event by recreating the watch on
> /etc/hosts, like this in the inner loop:
> 
>       if (buf.wd == watch && (buf.mask & IN_IGNORED) != 0)
>         {
>           /* Recreate watch */
>           watch = inotify_add_watch (fd, "/etc/hosts", IN_DELETE_SELF |
> IN_MODIFY /* | IN_MOVE */);
>           printf ("Added watch on /etc/hosts, as watch %d\n", watch);
>           if (watch < 0)
>             bark ("inotify_add_watch");
>         }
> 
> That's for sure surprising limitation of the interface.  Is this really how
> it's supposed to be used?

The watch descriptor returned by inotify_add_watch() refers to the inode, not
the path name.  This is analogous to open(2) returning a file descriptor that
refers to the inode, not the pathname.

So yes, adding IN_DELETE_SELF and IN_MOVE_SELF to the watches is a good way to
monitor whether changes to the file _name_ were made.

Note: inotify is an unreliable interface by design and the application should
provide a backup mechanism for theoretical cases when events are lost (e.g. by
checking the modification time of the file periodically).

Also see "Limitations and caveats" section in the inofity(7) manpage.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]