Hi Bob and Eric,
Thanks a lot for your promptly explanation. I've never thought that
symlinks could be used as a lock mechanism, and I need to admit that
this is a clever usage.
Rafael Torres
On Tue, Feb 1, 2011 at 1:50 PM, Bob Proulx <address@hidden> wrote:
> Rafael Torres wrote:
>> I've accidentally created a symbolic link that points to itself :
>>
>> [rtorres@rtorres tmp]$ ln -s tst tst
>> [rtorres@rtorres tmp]$ ls -la tst
>> lrwxrwxrwx 1 rtorres rtorres 3 Feb  1 11:59 tst -> tst
>
> Sure.
>
>> I've search in the list archive and didn't find any discussion about it.
>
> The topic of symlinks does come up periodically. Â I could refer to
> several random discussions in the archives but here are ones that I
> have taken an interest in.
>
> Â
>http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query=symlink+%2Bfrom%3Abob%40proulx.com&submit=Search!&idxname=bug-coreutils&max=10&result=normal&sort=score
>
>> Is it a small bug in symlink() or is there any purpose for such "feature" ?
>
> I think you are not understanding what 'ln -s' actually does. Â Let me
> give a little explanation.
>
> The 'ln -s' creates a symbolic link file. Â Symbolic links are special
> files that contain arbitrary strings of data. Â They doesn't actually
> link two files together but instead creates a special file with the
> specified string value. Â The filesystem will redirect through the
> value of the symbolic link for most filesystem operations. Â The
> symlink doesn't need to point to an existing file. Â It is a name
> resolution which happens at runtime. Â It might resolve to different
> files at different times. Â Not all operating systems support symlinks.
>
> Normally the content value in the symlink is a path to another file.
> However you can give it anything you want there. Â You can store the
> name of your dog there if you wish or use it to store a very small
> shopping list. Â This flexibility has proved to be a flexible and
> useful interface. Â It is often used for lock files storing the name of
> the locker for example.
>
> Creating a symlink that contains the name of the current file may have
> a use. Â I do not know. Â But there isn't any content scanning of the
> contents of the symlink file. Â Almost certainly someone someplace is
> using such a value as a flag of some sort. Â If you try to open such a
> symlink the kernel will redirect back to itself creating a loop that
> will exceed the configured loop count and be detected.
>
> Bob
>