coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: symlink pointing to itself


From: Bob Proulx
Subject: Re: symlink pointing to itself
Date: Tue, 1 Feb 2011 08:50:42 -0700
User-agent: Mutt/1.5.20 (2009-06-14)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]