tech-toolchain archive

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

Re: $ORIGIN (was: Re: make: ensure ${.MAKE} works)



On Wed, Apr 21, 2010 at 01:22:12PM -0400, Christos Zoulas wrote:
 > | If you exec "../bin/foo", that's all namei will resolve or touch, and
 > | that's the string that'll come back from namei. If we want an absolute
 > | path out, it needs getcwd, either in exec or in namei... and in exec
 > | is probably preferable.
 > 
 > That's right, and it affects in my opinion < 5% of the invocations,
 > since the majority of the execs are done via the shell and the shells
 > pass absolute paths to exec for commands that don't contain '/'.

Right.

 > | If we really want to support the feature we need to either buy into
 > | that overhead, or inspect the binary in some fashion to only do it in
 > | cases where it's going to be used.
 > | 
 > | AFAICT getcwd should be no more expensive than vnode_to_path if the
 > | parentage of the current directory is in the name cache, which should
 > | be the common case.
 > 
 > That's what vnode_to_path() does (it calls getcwd), so the cost is
 > the same.

I had convinced myself it was supposed to fail if it had to look
outside the cache, but that's only true for the first step.

 > I think what you propose is to call something like a
 > kernel realpath(path) and use this to set $ORIGIN which is fine
 > with me. I did not do it because I did not want to deal with path
 > canonicalization (eliminating ../.././// from the path, but I guess
 > that getcwd() does this for you if you call it with the full path?).

namei can already do enough of this to get by on (see for example
svr4_sys_resolvepath() in sys/compat/svr4/svr4_misc.c) and exec is
already using this (mis?)feature.

For the time being what we can do is take the path sent back from
namei, and if it's not absolute call getcwd and graft that onto the
front. This will in general yield a partially realpath'd path but I
don't think anyone will care.

In the long run I think a fully realpath'd path can be arranged,
either by calling getcwd first and handing the results to namei to
grind on, or by explicitly compacting any ..'s that appear in the
front of the namei result. I sort of favor the first because it makes
it possible to handle the emulation root properly, I think, but this
can be discussed later on.

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index