kdirwatch has problem to detect hard link change

David Faure faure at kde.org
Thu Feb 18 21:35:32 GMT 2010


On Friday 03 July 2009, sonald wrote:
> the problem comes up  when  I  traced the problem when using kcmshell4
> clock to set timezone, which is when you changed timezone second time,
> the setting just lost. I found the real problem is that
> KDirWatch loses watch on /etc/localtime.
> 
> I can reproduce the watch lose very easily:
>    # inotifywait -m /etc/localtime
>    # zic -l Asia/Shanghai
>    # zic -l Asia/Muscat
>    # touch /etc/localtime
> 
> After Change timezone to Muscat, subsequent changes to /etc/localtime
> won't be watched. because KDirWatch use inotify (I'm using a linux distro),
> which monitoring file with respect to inode , not dir entry.
> zic relinked ( hardlink ) /etc/localtime, so inotify just told attrib
> change ( st_nlink change ) of the original file.

I finally had a look at this (now that I have a better understanding of 
kdirwatch). -- and also because your change introduces the crash in bug 
222204.

I had a look at the sources for "zic", and it does unlink(/etc/localtime)
followed by link($timezone_file, /etc/localtime). Basically this is just like
unlink followed by recreating the file anew. Obviously you lose the kdirwatch
notifications about the file, since it was recreated from scratch. This is not 
related to hard link changes at all, you get the same behavior if you do

$ touch /tmp/foo
$ inotifywait -m /tmp/foo
$ rm /tmp/foo
$ touch /tmp/foo     # not noticed!

This is because watching a file means watching for modifications to the file.
Including deletion. But not including the file being recreated again, that's
a different file.

Since the watchers of /etc/localtime know that it is usually 
deleted+recreated, I think they should watch the directory /etc instead.
Then it works:

/etc/ DELETE localtime                             
/etc/ CREATE localtime 

Question 1: With this information, do you think you (or David Jarvie) can fix 
the kcm so that it watches the directory instead of (or in addition to) the 
file itself?

Question 2: can I revert the non-working (and even crashing) patch to 
KDirWatch?
It doesn't work because there is NO notification for the file re-appearing,
so no way to detect the hardlink change.

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Sponsored by Nokia to work on KDE, incl. Konqueror (http://www.konqueror.org).




More information about the kde-core-devel mailing list