Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Aug 2006 14:04:27 +0200
From:      des@des.no (Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?=)
To:        Mike Meyer <mwm@mired.org>
Cc:        Reko Turja <reko.turja@liukuma.net>, freebsd-hackers@freebsd.org
Subject:   Re: Aqcuiring full path to running process from outside the kernel
Message-ID:  <8664glnfhw.fsf@xps.des.no>
In-Reply-To: <17642.8303.746281.383448@bhuda.mired.org> (Mike Meyer's message of "Mon, 21 Aug 2006 17:06:55 -0400")
References:  <017601c6c486$6477c370$0a0aa8c0@rivendell> <17640.52899.432083.511555@bhuda.mired.org> <86sljqnzbz.fsf@xps.des.no> <17642.8303.746281.383448@bhuda.mired.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Mike Meyer <mwm@mired.org> writes:
> In <86sljqnzbz.fsf@xps.des.no>, Dag-Erling Sm=F8rgrav <des@des.no> typed:
> > You got it the wrong way around.  First pass argv[0] to realpath(3),
> > fall back to using $PATH only if realpath(3) fails (which it shouldn't
> > unless you've called chdir(2), chroot(2) or jail(2) earlier in the
> > process, or the executable was moved or removed)
> No, I got it the right way 'round. If the shell walks the PATH, then
> calling realpath(3) on argv[0] is the wrong thing to do, as it'll
> resolve the path relative to the pwd.

but argv[0] is either an absolute path or a path relative to pwd,
unless your shell is broken.

des@xps ~% cat >bin/foo
#!/bin/sh
echo $0 $@
des@xps ~% chmod a+rx bin/foo
des@xps ~% ./bin/foo
./bin/foo
des@xps ~% foo
/home/des/bin/foo

DES
--=20
Dag-Erling Sm=F8rgrav - des@des.no



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8664glnfhw.fsf>