perf utils: Readlink /proc/self/exe to find the perf binary
authorTommi Rantala <tommi.t.rantala@nokia.com>
Wed, 22 Mar 2017 13:06:24 +0000 (15:06 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 27 Mar 2017 18:37:54 +0000 (15:37 -0300)
Simplification: it is easier to open /proc/self/exe than /proc/$pid/exe.

Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20170322130624.21881-7-tommi.t.rantala@nokia.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/header.c

index cf22962ce725077277bc7be6d79cb30682709fe7..ef09f26e67da0b95b9455a8fc10167fcb70bbb8d 100644 (file)
@@ -370,15 +370,11 @@ static int write_cmdline(int fd, struct perf_header *h __maybe_unused,
                         struct perf_evlist *evlist __maybe_unused)
 {
        char buf[MAXPATHLEN];
-       char proc[32];
        u32 n;
        int i, ret;
 
-       /*
-        * actual atual path to perf binary
-        */
-       sprintf(proc, "/proc/%d/exe", getpid());
-       ret = readlink(proc, buf, sizeof(buf) - 1);
+       /* actual path to perf binary */
+       ret = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
        if (ret <= 0)
                return -1;