Xref: utzoo comp.unix.wizards:8369 comp.sources.d:2070 Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pasteur!ucbvax!unisoft!hoptoad!gnu From: gnu@hoptoad.uucp (John Gilmore) Newsgroups: comp.unix.wizards,comp.sources.d Subject: Finding where an executable was run from -- a proposal. Message-ID: <4527@hoptoad.uucp> Date: 11 May 88 01:35:29 GMT References: <67@uvaarpa.virginia.edu> <6800012@cpe> Organization: Grasshopper Group in San Francisco Lines: 35 tif@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@toad.com "Use the Source, Luke...."