Ultrix symbolic link strangeness...

Tom Arons arons at ash.eecs.ucdavis.edu
Wed Apr 3 05:43:06 AEST 1991


In article <C74Z93R at dri.com> frotz at dri.com (Frotz) writes:

   The following is a description of an annoyance bug.  If you have any
   comments or workarounds, please speak up. 

   Problem setup:	% ln -s /symbolic_dir /dir1/real_dir
		   % cd /symbolic_dir
		   % pwd

   Problem:	The output from pwd is "/symbolic_dir" not "/dir1/real_dir"
		   as expected.

This is caused by a call to stat() rather than lstat() in ultrix
versions of getwd() which is what pwd uses.  getwd() constructs a path
name by working its way up to "/" stat'ing the current directory, then
changing to the parent directory and stat'ing each directory entry
looking for a matching inode number.  When a match is found, that
directory entry is prepended to the path name.  Because stat is used
instead of lstat there is no way to tell the difference between a sym
link and the file it points to.  You get the path name component of
which ever directory entry readdir returns first.  Because the "real"
directory entry usually comes before a symlink in a directory you
ususally don't see this behavior.  You can force any order you like,
and thus get the "real" name, by a combination of mkdir's, rmdir's and
mv's in the directory that contains the objectionable sym link.


Tom Arons			Internet: arons at eecs.ucdavis.edu
EE/CS Department		Bitnet:   tgarons at ucdavis
University of California	UUCP:     {lll-crg, ucbvax}!ucdavis!iris!arons
Davis, CA 95616			Phone:    (916) 752-1750



More information about the Comp.unix.ultrix mailing list