Subject: Re: build breaks w/ read-only sources
To: David Laight <david@l8s.co.uk>
From: Greywolf <greywolf@starwolf.com>
List: current-users
Date: 10/30/2003 12:32:20
Thus spake David Laight ("DL> ") sometime Today...

DL> > That's fine; our builtin pwd does a physical walk anyway.
DL>
DL> But that isn't what it is required to do...
DL> Both /bin/pwd and the builtin pwd are required (by default) to report
DL> the name including any symlinks.

I think we're somehow on the same page here but not quite understanding
each other.

They are required to report the Current Working Directory along the physical
path; certainly /bin/pwd is, as that's the only way it can divine the
current working directory.

#ifndef I_KNOW_HOW_PWD_WORKS

The premise of /bin/pwd (and, in fact, getcwd(3)) is pretty straightforward.
We keep no pathname information in the context of the current process;
in particular, p->cwd is a vnode.  In order to determine the current
working directory, we lstat ., and readdir .. until we get the entry whose
dev/ino pair match that of ., then we note ..'s stats and readdir ../..
until we get that entry, all the way up until the stats of ../.. match
those of .. at the top of the tree (imagine the requisite levels of reference
to .., ../.., ../../.., etc.).

In our implementation, it is not possible for getcwd to determine the path
along a symlink, because a symlink's stats will never match those of its
target.  Any implementation which behaves otherwise is broken.

#endif

In our /bin/sh, pwd did the same thing (at least, as I am given to understand,
until recently).  Last I tested, pwd did NOT show symlinks, but showed
the true path.  pwd -P means 'follow the physical path and ignore ${PWD}'.
pwd -L means 'show me what's been stuffed into ${PWD}, which could be
a link-infested path'.

But /bin/pwd cannot possibly "include any symlinks" in its translation
of the path -- it will resolve to a unique physical path (unless someone's
done the craziness of hardlinking a directory and/or created a loop
in the filesystem graph).

So did my reference to "physical walk", "-P", "what bin sh does" and the
like somehow manage to carry across different meanings than those which
might have been in your mental cache?

				--*greywolf;
--
NetBSD: Agnostics in the Platform Religious Wars.