diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/cgroup.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index 8fdee24725a7..eafbf11442b2 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c | |||
@@ -12,8 +12,8 @@ cgroupfs_find_mountpoint(char *buf, size_t maxlen) | |||
12 | { | 12 | { |
13 | FILE *fp; | 13 | FILE *fp; |
14 | char mountpoint[PATH_MAX + 1], tokens[PATH_MAX + 1], type[PATH_MAX + 1]; | 14 | char mountpoint[PATH_MAX + 1], tokens[PATH_MAX + 1], type[PATH_MAX + 1]; |
15 | char path_v1[PATH_MAX + 1], path_v2[PATH_MAX + 2], *path; | ||
15 | char *token, *saved_ptr = NULL; | 16 | char *token, *saved_ptr = NULL; |
16 | int found = 0; | ||
17 | 17 | ||
18 | fp = fopen("/proc/mounts", "r"); | 18 | fp = fopen("/proc/mounts", "r"); |
19 | if (!fp) | 19 | if (!fp) |
@@ -24,31 +24,43 @@ cgroupfs_find_mountpoint(char *buf, size_t maxlen) | |||
24 | * and inspect every cgroupfs mount point to find one that has | 24 | * and inspect every cgroupfs mount point to find one that has |
25 | * perf_event subsystem | 25 | * perf_event subsystem |
26 | */ | 26 | */ |
27 | path_v1[0] = '\0'; | ||
28 | path_v2[0] = '\0'; | ||
29 | |||
27 | while (fscanf(fp, "%*s %"STR(PATH_MAX)"s %"STR(PATH_MAX)"s %" | 30 | while (fscanf(fp, "%*s %"STR(PATH_MAX)"s %"STR(PATH_MAX)"s %" |
28 | STR(PATH_MAX)"s %*d %*d\n", | 31 | STR(PATH_MAX)"s %*d %*d\n", |
29 | mountpoint, type, tokens) == 3) { | 32 | mountpoint, type, tokens) == 3) { |
30 | 33 | ||
31 | if (!strcmp(type, "cgroup")) { | 34 | if (!path_v1[0] && !strcmp(type, "cgroup")) { |
32 | 35 | ||
33 | token = strtok_r(tokens, ",", &saved_ptr); | 36 | token = strtok_r(tokens, ",", &saved_ptr); |
34 | 37 | ||
35 | while (token != NULL) { | 38 | while (token != NULL) { |
36 | if (!strcmp(token, "perf_event")) { | 39 | if (!strcmp(token, "perf_event")) { |
37 | found = 1; | 40 | strcpy(path_v1, mountpoint); |
38 | break; | 41 | break; |
39 | } | 42 | } |
40 | token = strtok_r(NULL, ",", &saved_ptr); | 43 | token = strtok_r(NULL, ",", &saved_ptr); |
41 | } | 44 | } |
42 | } | 45 | } |
43 | if (found) | 46 | |
47 | if (!path_v2[0] && !strcmp(type, "cgroup2")) | ||
48 | strcpy(path_v2, mountpoint); | ||
49 | |||
50 | if (path_v1[0] && path_v2[0]) | ||
44 | break; | 51 | break; |
45 | } | 52 | } |
46 | fclose(fp); | 53 | fclose(fp); |
47 | if (!found) | 54 | |
55 | if (path_v1[0]) | ||
56 | path = path_v1; | ||
57 | else if (path_v2[0]) | ||
58 | path = path_v2; | ||
59 | else | ||
48 | return -1; | 60 | return -1; |
49 | 61 | ||
50 | if (strlen(mountpoint) < maxlen) { | 62 | if (strlen(path) < maxlen) { |
51 | strcpy(buf, mountpoint); | 63 | strcpy(buf, path); |
52 | return 0; | 64 | return 0; |
53 | } | 65 | } |
54 | return -1; | 66 | return -1; |