summaryrefslogtreecommitdiff
path: root/tools/perf/util/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/util.c')
-rw-r--r--tools/perf/util/util.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 8b893de35f77..8f7cd32f524d 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -77,8 +77,6 @@ bool sysctl__nmi_watchdog_enabled(void)
return nmi_watchdog;
}
-bool test_attr__enabled;
-
bool exclude_GH_default;
bool perf_host = true;
@@ -380,15 +378,9 @@ int perf_event_paranoid(void)
bool perf_event_paranoid_check(int max_level)
{
- bool used_root;
-
- if (perf_cap__capable(CAP_SYS_ADMIN, &used_root))
- return true;
-
- if (!used_root && perf_cap__capable(CAP_PERFMON, &used_root))
- return true;
-
- return perf_event_paranoid() <= max_level;
+ return perf_cap__capable(CAP_SYS_ADMIN) ||
+ perf_cap__capable(CAP_PERFMON) ||
+ perf_event_paranoid() <= max_level;
}
int perf_tip(char **strp, const char *dirpath)
@@ -421,11 +413,21 @@ out:
char *perf_exe(char *buf, int len)
{
- int n = readlink("/proc/self/exe", buf, len);
+ int n;
+
+ if (len <= 0)
+ return buf;
+
+ n = readlink("/proc/self/exe", buf, len - 1);
if (n > 0) {
buf[n] = 0;
return buf;
}
+ if (len < (int)sizeof("perf")) {
+ buf[0] = '\0';
+ return buf;
+ }
+
return strcpy(buf, "perf");
}
@@ -547,3 +549,11 @@ int scandirat(int dirfd, const char *dirp,
return err;
}
#endif
+
+/* basename version that takes a const input string */
+const char *perf_basename(const char *path)
+{
+ const char *base = strrchr(path, '/');
+
+ return base ? base + 1 : path;
+}