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
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/
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,