Addition to unix: raw ByteString APIs

Brandon Allbery allbery.b at gmail.com
Mon Nov 14 18:45:06 CET 2011


On Mon, Nov 14, 2011 at 12:05, Balazs Komuves <bkomuves at gmail.com> wrote:

> Unfortunately, there is no standardized way on different unix systems
> to access the path of the executable running (it's not even fully
> clear what it means in the presence of symlinks, etc). Actually it seems
> to be impossible to do this (without argv[0]) on certain BSD systems.


Also note:

- argv[0] won't be a full pathname if the program was found via $PATH search

- it is possible for users to pass arbitrary argv[0] to the exec() family
of system calls

- some programs use special argv[0] values (this probably doesn't
practically matter), notably shells look for a leading "-" (which is
normally provided by "login" or "sshd" etc.) to indicate a login shell that
should source ~/.profile etc.

- there are various other special cases, such as a number of Unixlikes
implementing setuid shell scripts securely by passing a /dev/fd/* reference
as argv[0] to avoid symlink attacks.  Again, you *probably* don't need to
care about this one, but there may be others on various systems.

In short, argv[0] should not be relied on as the executable name.

(The usual way this is managed is that the real executable is something
like foo.real and foo is a shell script which passes in the path to
foo.real as a parameter.  During installation/configuration the shell
script is modified as necessary to provide the correct path.)

-- 
brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20111114/63aa1b33/attachment.htm>


More information about the Libraries mailing list