aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorFranck Bui-Huu <fbuihuu@gmail.com>2010-12-10 16:06:26 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-12-16 06:41:45 -0500
commit68a7a771ad0e2959983729bf88cbc74a7014438f (patch)
tree6d63982c1bd04aa461b4fdb59996cf6faad6fba4 /tools/perf
parentc3a34e06db25a8c74e196517732d65cdb56028ec (diff)
perf buildid-cache: Fix symbolic link handling
This was broken since link(2) doesn't dereference symbolic links. Instead 'filename' becomes a symbolic link to the same file that 'name' refers to. This had the bad effect to create dangling symlinks in the case that even can't be removed with perf-buildid-cache(1). LKML-Reference: <m38vzxxrql.fsf@gmail.com> Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/header.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 64a85bafde63..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;
302out_free: 303out_free:
304 free(realname);
303 free(filename); 305 free(filename);
304 free(linkname); 306 free(linkname);
305 return err; 307 return err;