>>>> "Justin" == Justin Vallon
<vallon(a)mindspring.com> writes:
Justin> On Thu, 18 Feb 1999, Martin Buchholz wrote:
> I tried to solve this problem in the distant past by adding this
hack
> to all the scripts in lib-src:
>
> PATH=${PATH:-/usr/bin:/bin}:`dirname $0 2>/dev/null`; export PATH
>
> This hack requires that $0 contain the full path to the script, and
> that dirname exists. Why would this this not be the case?
Justin> [ I didn't realize there would be a quiz. ]
Justin> You can execl("/bin/ls", "ha-ha", "-l", 0),
though it might give ls a
Justin> headache if it doesn't know its name. Mostly, $0 will be either a
Justin> relative or absolute path to yourself, but it depends on the shell/execer.
In our case, it is intended that xemacs will be execing the programs,
but the programs should not fall off over if they are invoked `by
hand' or by a malicious hacker determined to find bugs. It is not yet
the case that you have to be clever to find bugs in XEmacs.
Justin> A perl module (FindBin) does some further sanity checks: Check if $0
Justin> exists. Make it absolute if relative. If $0 is only a basename
"cat",
Justin> search for $0 in $PATH to get the fullpath of $0 (this last check would be
Justin> pointless if trying to get the dir of $0, of course). Fail if all of
Justin> these attempts fail.
We should be similarily paranoid. But it's harder and more expensive
in a shell script.
Martin