Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf tools: Add perf_exe() helper to find perf binary

Also convert one existing user.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20190224153722.27020-9-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Andi Kleen and committed by
Arnaldo Carvalho de Melo
94816add 4b6ac811

+15 -9
+3 -9
tools/perf/util/header.c
··· 527 527 static int write_cmdline(struct feat_fd *ff, 528 528 struct perf_evlist *evlist __maybe_unused) 529 529 { 530 - char buf[MAXPATHLEN]; 531 - u32 n; 532 - int i, ret; 530 + char pbuf[MAXPATHLEN], *buf; 531 + int i, ret, n; 533 532 534 533 /* actual path to perf binary */ 535 - ret = readlink("/proc/self/exe", buf, sizeof(buf) - 1); 536 - if (ret <= 0) 537 - return -1; 538 - 539 - /* readlink() does not add null termination */ 540 - buf[ret] = '\0'; 534 + buf = perf_exe(pbuf, MAXPATHLEN); 541 535 542 536 /* account for binary path */ 543 537 n = perf_env.nr_cmdline + 1;
+10
tools/perf/util/util.c
··· 568 568 569 569 return tip; 570 570 } 571 + 572 + char *perf_exe(char *buf, int len) 573 + { 574 + int n = readlink("/proc/self/exe", buf, len); 575 + if (n > 0) { 576 + buf[n] = 0; 577 + return buf; 578 + } 579 + return strcpy(buf, "perf"); 580 + }
+2
tools/perf/util/util.h
··· 77 77 void perf_set_singlethreaded(void); 78 78 void perf_set_multithreaded(void); 79 79 80 + char *perf_exe(char *buf, int len); 81 + 80 82 #ifndef O_CLOEXEC 81 83 #ifdef __sparc__ 82 84 #define O_CLOEXEC 0x400000