diff options
Diffstat (limited to 'tools/perf/util/header.c')
| -rw-r--r-- | tools/perf/util/header.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index d7e67b167ea3..7cba0551a565 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
| @@ -265,15 +265,16 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, | |||
| 265 | const char *name, bool is_kallsyms) | 265 | const char *name, bool is_kallsyms) |
| 266 | { | 266 | { |
| 267 | const size_t size = PATH_MAX; | 267 | const size_t size = PATH_MAX; |
| 268 | char *filename = malloc(size), | 268 | char *realname = realpath(name, NULL), |
| 269 | *filename = malloc(size), | ||
| 269 | *linkname = malloc(size), *targetname; | 270 | *linkname = malloc(size), *targetname; |
| 270 | int len, err = -1; | 271 | int len, err = -1; |
| 271 | 272 | ||
| 272 | if (filename == NULL || linkname == NULL) | 273 | if (realname == NULL || filename == NULL || linkname == NULL) |
| 273 | goto out_free; | 274 | goto out_free; |
| 274 | 275 | ||
| 275 | len = snprintf(filename, size, "%s%s%s", | 276 | len = snprintf(filename, size, "%s%s%s", |
| 276 | debugdir, is_kallsyms ? "/" : "", name); | 277 | debugdir, is_kallsyms ? "/" : "", realname); |
| 277 | if (mkdir_p(filename, 0755)) | 278 | if (mkdir_p(filename, 0755)) |
| 278 | goto out_free; | 279 | goto out_free; |
| 279 | 280 | ||
| @@ -283,7 +284,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, | |||
| 283 | if (is_kallsyms) { | 284 | if (is_kallsyms) { |
| 284 | if (copyfile("/proc/kallsyms", filename)) | 285 | if (copyfile("/proc/kallsyms", filename)) |
| 285 | goto out_free; | 286 | goto out_free; |
| 286 | } else if (link(name, filename) && copyfile(name, filename)) | 287 | } else if (link(realname, filename) && copyfile(name, filename)) |
| 287 | goto out_free; | 288 | goto out_free; |
| 288 | } | 289 | } |
| 289 | 290 | ||
| @@ -300,6 +301,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, | |||
| 300 | if (symlink(targetname, linkname) == 0) | 301 | if (symlink(targetname, linkname) == 0) |
| 301 | err = 0; | 302 | err = 0; |
| 302 | out_free: | 303 | out_free: |
| 304 | free(realname); | ||
| 303 | free(filename); | 305 | free(filename); |
| 304 | free(linkname); | 306 | free(linkname); |
| 305 | return err; | 307 | return err; |
| @@ -946,11 +948,16 @@ perf_header__find_attr(u64 id, struct perf_header *header) | |||
| 946 | 948 | ||
| 947 | /* | 949 | /* |
| 948 | * We set id to -1 if the data file doesn't contain sample | 950 | * We set id to -1 if the data file doesn't contain sample |
| 949 | * ids. Check for this and avoid walking through the entire | 951 | * ids. This can happen when the data file contains one type |
| 950 | * list of ids which may be large. | 952 | * of event and in that case, the header can still store the |
| 953 | * event attribute information. Check for this and avoid | ||
| 954 | * walking through the entire list of ids which may be large. | ||
| 951 | */ | 955 | */ |
| 952 | if (id == -1ULL) | 956 | if (id == -1ULL) { |
| 957 | if (header->attrs > 0) | ||
| 958 | return &header->attr[0]->attr; | ||
| 953 | return NULL; | 959 | return NULL; |
| 960 | } | ||
| 954 | 961 | ||
| 955 | for (i = 0; i < header->attrs; i++) { | 962 | for (i = 0; i < header->attrs; i++) { |
| 956 | struct perf_header_attr *attr = header->attr[i]; | 963 | struct perf_header_attr *attr = header->attr[i]; |
