Finding where an executable was run from -- a proposal.
John Gilmore
gnu at hoptoad.uucp
Wed May 11 11:35:29 AEST 1988
tif at cpe.UUCP wrote:
> ...it sounds like perl should have a special variable
> that is like $0 only contains a full path.
I have often wanted exactly this for C utilities. Wouldn't it be nice
if you didn't have to build in the names of your control files -- if
the executable could derive the names of its config files from its own name?
The problem is that Unix doesn't provide a way to tell your own name.
What is passed in argv[0] need not bear any relation to the name of
the program (and often doesn't, if the shell has searched PATH to find
the executable). On the other hand, the first argument to exec() is
always the correct path of the executable (either an absolute or
relative path). But it's not available to the executed program.
If exec() would pass this value to the executed program, say as
argv[-1], then a program could reliably know its own name, and apply a
simple transformation to it to find its data files (e.g. for program
"XXXXXX/foo", its data files are found in "XXXXXX/lib/foo/whatever").
This works for all values of XXXXXX, whether absolute or relative.
For a subsystem like uucp, you would turn e.g. XXXXXX/uucico into
XXXXXX/lib/uucp/whatever (replace program name with subsystem name).
This would make lots of application programs easier to install; you just
copy it into somewhere on your PATH and it will run. For all those "shrink
wrap applications" that ABI is likely to provide, this would be a major win.
It would also reduce the volume of arcane knowledge required to run
a Unix system (e.g. where are the netnews control files kept? How about
crontab? How about sendmail configs? How about inet daemon config?)
If anyone implements this, I recommend providing a #define AV_EXECNAME -1
and documenting that argv[AV_EXECNAME] is the pathname given to exec().
No sense embedding another magic number (-1) into programs...
--
John Gilmore {sun,pacbell,uunet,pyramid,ihnp4}!hoptoad!gnu gnu at toad.com
"Use the Source, Luke...."
More information about the Comp.unix.wizards
mailing list