|
From: John R.
|
Rodrigo Dominguez wrote:
> Why use readlink /proc/self/exe instead of argv[0] in launcher-linux.c?
readlink("/proc/self/exe",,) is a closer approximation to the path
of execve(path, argv, envp). The operating system ignores argv[0]
in determining what to exec. It is only a user-level [usually, shell]
convention that argv[0]==path in many cases.
readlink("/proc/self/exe",,) can fail in corner cases because
/proc/self/exe can disappear if all the pages from the original execve
are unmapped. Some runtime program de-compressors are that good.
I wrote a patch in the Linux -mm tree of pending changes:
execve filename: document and export via auxiliary vector
which adds a new AT_EXECFN that documents the fact that Linux
puts the pathname of execve into the new address space, and has
for over a dozen years. This is also the perfect place and method
for virtualizers (valgrind, wine, ...) to change as appropriate.
In the meantime, (1+ strlen(envp[-1+ n_env]) + envp[-1+ n_env])
happens to be the path, for the original envp and n_env [and
no putenv() or other clobberage, etc.]
--
|