[prev in list] [next in list] [prev in thread] [next in thread] 

List:       coreutils
Subject:    Re: symlink pointing to itself
From:       Rafael Torres <rdtorres () gmail ! com>
Date:       2011-02-01 16:47:01
Message-ID: AANLkTinT1s8c4zBVw_wiTXD0t8p4zf5DLhhHGScKFiY8 () mail ! gmail ! com
[Download RAW message or body]

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 <bob@proulx.com> 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
> 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic