>>> Is there any way to get actual _full_ name of current executable,
>> You can try reading the /proc/self/exe-symlink. But a file can
>> have many different names on a filesystem with hard link
>> support, so this may or may not help.
> The executable may also have zero names.
Beginning in Linux 2.6.29, the kernel sets the AT_EXECFN entry of
the ELF auxiliary vector (see /usr/include/elf.h) to the pathname
that was specified to execve(). All Linux 2.x.y kernels put that
pathname into the new address space, but AT_EXECFN documents it.
Most of the time you can also get that pathname via
(1+ strlen(envp[-1+ n_env]) + envp[-1+ n_env])
where envp is the vector of environment variables, and n_env
is their number. Calling putenv(), or otherwise overwriting
the environment vector or environment strings, may invalidate
the expected results.
Independent of how any potential answer is obtained, and independent
of whether the filesystem supports hardlinks, and independent of
whether the potential answer is a rooted or a relative pathname,
there is a race condition. The pathname at the time of execve()
may have designated a different collection of bytes (file) then,
than it does now. It is difficult to prevent such a difference
in all cases. You can come close
if the medium that holds the bytes is physically read-only,
and if the filesystem that holds the bytes is mounted read-only,
and if there are no other mounts of the filesystem that holds the bytes,
and if the mount point, and all its ancestors, also are read-only
and have no conflicting mounts,
and if there are no symbolic links in any of the relevant paths.
That's a lot to ask, and usually it isn't necessary.
One very legitimate use of the pathname is to be the source
for expanding the dynamic string token "$ORIGIN" in DT_RUNPATH,
so that an executable and its associated "private" shared libraries
can be relocated easily in a filesystem. [A Solaris feature copied by
glibc; never documented. glibc trusts readlink("/proc/self/exe",)
in this case.] The AT_EXECFN token also is the perfect place
for a virtualizer program to adjust the environment.
--