Home > proc self > error resolving symlink /proc/self/exe

Error Resolving Symlink /proc/self/exe

Contents

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About what is proc self exe Us Learn more about Stack Overflow the company Business Learn more about hiring readlink /proc/self/exe developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the linux proc self exe Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to handle readlink() of “/proc/self/exe”

_nsgetexecutablepath

when executable is replaced during execution? up vote 6 down vote favorite In my C++ application, my application does an execv() in a fork()ed child process to use the same executable to process some work in a new child process with different arguments that communicates with pipes to the parent process. To get the pathname to self, I execute the following code on the Linux port c++ readlink (I have different code on Macintosh): const size_t bufSize = PATH_MAX + 1; char dirNameBuffer[bufSize]; // Read the symbolic link '/proc/self/exe'. const char *linkName = "/proc/self/exe"; const int ret = int(readlink(linkName, dirNameBuffer, bufSize - 1)); However, if while the executable is running, I replace the executable with an updated version of the binary on disk, the readlink() string result is: "/usr/local/bin/myExecutable (deleted)" I understand that my executable has been replaced by a newer updated version and the original for /proc/self/exe is now replaced, however, when I go to execv() it now fails with the errno 2 - No such file or directory. due to the extra trailing " (deleted)" in the result. I would like the execv() to either use the old executable for self, or the updated one. I could just detect the string ending with " (deleted)" and modify it to omit that and resolve to the updated executable, but that seems clumsy to me. How can I execv() the current executable (or its replacement if that is easier) with a new set of arguments when the original executable has been replaced by an updated one during execution? c++ linux exec fork self-reference share

is involved Summary /proc/self/exe is not set properly when valgrind is involved Status RESOLVED FIXED Product: valgrind Classification: Unclassified Component: general Version: 2.1.2 Platform: unspecified Linux Importance: NOR normal (vote) TargetMilestone: --- Assigned To: c readlink example Julian Seward URL: Keywords: Depends on: Blocks: Show dependency tree /graph Reported: 2004-08-10 16:20

Realpath

UTC by smile Modified: 2005-01-20 20:24 UTC (History) CC List: 2 users (show) frank.wallingford rjwalsh See Also: Latest Commit: Version Fixed In:

Dirname

Description smile 2004-08-10 16:20:48 UTC Version: 2.1.2 (using KDE KDE 3.2.3) Installed from: Unspecified Compiler: gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-34) OS: Linux The link /proc/self/exe has no target when a program is run http://stackoverflow.com/questions/28953307/how-to-handle-readlink-of-proc-self-exe-when-executable-is-replaced-during under valgrind. A simple testcase: $ ls -l /proc/self/exe lrwxrwxrwx 1 msadasiv g900 0 Aug 10 07:09 /proc/self/exe -> /bin/ls $ valgrind --tool=addrcheck ls -l /proc/self/exe ==12470== Warning: ignored attempt to set SIGKILL handler in sigaction(); ==12470== the SIGKILL signal is uncatchable ==12470== Warning: ignored attempt to set SIGSTOP handler in sigaction(); ==12470== the SIGSTOP signal is uncatchable ls: cannot read symbolic link /proc/self/exe: No such file or directory lrwxrwxrwx 1 msadasiv g900 https://bugs.kde.org/show_bug.cgi?id=86921 0 Aug 10 07:08 /proc/self/exe Another testcase: Following is a simple C code just printing the content of the link $ cat proc_self.c #include #include #include #include /*Finds the path containing the currently running program executable. The path is placed into BUFFER,which is of length LEN.Returns the number of characters in the path,or -1 on error.*/ int main () { char path [PATH_MAX ]; /*Read the target of /proc/self/exe.*/ if (readlink ("/proc/self/exe", path, PATH_MAX) <= 0){ printf("%s\n","readline error"); return -1; } else { printf("%s\n", path); } return 0; } $ gcc -g -o proc_self proc_self.c $ valgrind --tool=addrcheck -q proc_self readline error $ proc_self /home/msadasiv/prgs/exe/proc_self $ /proc/self though points to the right pid. /proc/self/exe has no target Comment 1 Tom Hughes 2004-08-10 17:01:23 UTC I suspect this will be very hard to fix. The problem is that as far as the kernel is concerned, the executable is /usr/bin/valgrind, but that has actually been unmapped once stage2 is loaded. What proc_exe_link() in fs/proc/base.c in the kernel does is look through the target process's memory mappings for one with the VM_EXECUTABLE flag set and then return the file from which that memory is mapped as the target of the link. Because /usr/bin/valgrind has been unmapped it doesn't find such a mapping so returns ENOENT instea

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and http://unix.stackexchange.com/questions/197854/how-does-the-proc-pid-exe-symlink-differ-from-ordinary-symlinks policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges https://github.com/docker/docker/issues/11462 Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: proc self Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How does the /proc//exe symlink differ from ordinary symlinks? up vote 11 down vote favorite If I start a process and then delete the binary of it, I can still recover it from /proc//exe: $ cp `which sleep` proc self exe . $ ./sleep 10m & [1] 13728 $ rm sleep $ readlink /proc/13728/exe /tmp/sleep (deleted) $ cp /proc/13728/exe ./sleep-copy $ diff sleep-copy `which sleep` && echo not different not different $ stat /proc/13728/exe File: ‘/proc/13728/exe’ -> ‘/tmp/sleep (deleted)’ Size: 0 Blocks: 0 IO Block: 1024 symbolic link On the other hand, if I make a symbolic link myself, delete the target and attempt to copy: cp: cannot stat ‘sleep’: No such file or directory /proc is an interface to the kernel. So does this symbolic link actually point to the copy loaded in memory, but with a more useful name? How does the exe link work, exactly? linux symlink proc share|improve this question edited Apr 22 '15 at 11:20 terdon♦ 87.3k16146252 asked Apr 22 '15 at 11:08 muru 18.3k33267 add a comment| 2 Answers 2 active oldest votes up vote 8 down vote /proc//exe does not follow the normal semantics for symbolic links. Technically this might count as a violation of POSIX, but /proc is a special filesystem after all. /proc//exe appears to be a symlink when you stat it. This is a convenient way for

Sign in Pricing Blog Support Search GitHub This repository Watch 2,917 Star 35,890 Fork 10,557 docker/docker Code Issues 1,814 Pull requests 154 Projects 0 Wiki Pulse Graphs New issue /proc/self/fd/{0,1,2} are not valid (with --tty) #11462 Open pwaller opened this Issue Mar 18, 2015 · 32 comments Projects None yet Labels area/runtime Milestone No milestone Assignees No one assigned 8 participants pwaller commented Mar 18, 2015 This is probably the root cause of #6880 and #8755. Reproduced on 1.4.1 and 1.5.0. Steps to reproduce: $ docker run -ti --rm ubuntu ls -l /proc/self/fd lrwx------ 1 root root 64 Mar 18 11:32 0 -> /25 lrwx------ 1 root root 64 Mar 18 11:32 1 -> /25 lrwx------ 1 root root 64 Mar 18 11:32 2 -> /25 lr-x------ 1 root root 64 Mar 18 11:32 3 -> /proc/1/fd Expected: /fd/{0,1,2} symlinks should point to the same thing as docker run -ti --rm ubuntu tty. Got: they point to some random point on the root of the filesystem which doesn't exist. Effect: This breaks the command tty (and therefore tmux and various other programs) from a docker exec into the container. The reason is that readlink(/proc/self/fd/0) returns a path that doesn't exist. It also breaks any program which uses /dev/std{in,out,err}, because these are symlinks to items in the /proc/self/fd/ directory. phemmer commented Mar 18, 2015 It looks like docker is using the host's /dev/pts mount for containers. All TTYs that docker creates aren't showing up in /dev/pts, only TTYs created once inside the container (tmux/screen/etc). Note that these "symlinks" aren't real symlinks. You can still use them (echo foo > /proc/self/fd/1) as they're magic files handled by the kernel. They just link to a TTY outside the container, so they can't be properly handled by readlink(2). # docker run -ti fedora:20 sh -c 'echo foo > /proc/self/fd/2' foo # docker run -ti fedora:20 sh -c 'echo foo > /dev/stderr' foo So basically unless something is trying to perform a readlink(2) call, this shouldn't matter. pwaller commented Mar 18, 2015 Yes, tty tries to readlink. I also suspect that tmux does as well. phemmer commented Mar 22,

 

Related content

No related pages.