Re: Aqcuiring full path to running process from outside the kernel
- From: Mike Meyer <mwm-keyword-freebsdhackers2.e313df@xxxxxxxxx>
- Date: Mon, 21 Aug 2006 17:06:55 -0400
In <86sljqnzbz.fsf@xxxxxxxxxx>, Dag-Erling Smørgrav <des@xxxxxx> typed:
Mike Meyer <mwm-keyword-freebsdhackers2.e313df@xxxxxxxxx> writes:
However, you can also make a best effort. Check argv[0] to see if youYou got it the wrong way around. First pass argv[0] to realpath(3),
have an absolute path. If not, do what the shell would do to find the
executable - look for it on $PATH. Once you've found it, call
realpath(3) to canonicalize the path.
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. In particular, since realpath(3)
doesn't care if the last component of the path actually exists or not,
any argv[0] that doesn't have a '/' in it will be mapped to that name
in the current directory. That's assuming that the shell doesn't pass
an argv[0] that's the full path to the executable; if the shell does
that, then my version still works. Since there are shells that don't
do that, you gotta walk the PATH before calling realpath(3) if the
shell walked the PATH.
Testing for absolute paths is the wrong way test for "did the shell
walk PATH", though. You should test for any occurrence of '/' instead,
but being absolutely right about it may involve changing the test to
match the shell being used.
<mike
--
Mike Meyer <mwm@xxxxxxxxx> http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"
- Follow-Ups:
- Re: Aqcuiring full path to running process from outside the kernel
- From: Dag-Erling Smørgrav
- Re: Aqcuiring full path to running process from outside the kernel
- References:
- Aqcuiring full path to running process from outside the kernel
- From: Reko Turja
- Re: Aqcuiring full path to running process from outside the kernel
- From: Mike Meyer
- Re: Aqcuiring full path to running process from outside the kernel
- From: Dag-Erling Smørgrav
- Aqcuiring full path to running process from outside the kernel
- Prev by Date: Re: Relative paths [was: Path transformation]
- Next by Date: Re: global data via module howto
- Previous by thread: Re: Aqcuiring full path to running process from outside the kernel
- Next by thread: Re: Aqcuiring full path to running process from outside the kernel
- Index(es):
Relevant Pages
|
|