* [PATCH] perf-tools: fix perf-buildid-cache when passing a symbolic link
@ 2010-12-10 21:06 Franck Bui-Huu
2010-12-22 11:28 ` [tip:perf/urgent] perf buildid-cache: Fix symbolic link handling tip-bot for Franck Bui-Huu
0 siblings, 1 reply; 2+ messages in thread
From: Franck Bui-Huu @ 2010-12-10 21:06 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo; +Cc: lkml, linux-perf-users
From: Franck Bui-Huu <fbuihuu@gmail.com>
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).
Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
| 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 64a85ba..7cba055 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,
const char *name, bool is_kallsyms)
{
const size_t size = PATH_MAX;
- char *filename = malloc(size),
+ char *realname = realpath(name, NULL),
+ *filename = malloc(size),
*linkname = malloc(size), *targetname;
int len, err = -1;
- if (filename == NULL || linkname == NULL)
+ if (realname == NULL || filename == NULL || linkname == NULL)
goto out_free;
len = snprintf(filename, size, "%s%s%s",
- debugdir, is_kallsyms ? "/" : "", name);
+ debugdir, is_kallsyms ? "/" : "", realname);
if (mkdir_p(filename, 0755))
goto out_free;
@@ -283,7 +284,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
if (is_kallsyms) {
if (copyfile("/proc/kallsyms", filename))
goto out_free;
- } else if (link(name, filename) && copyfile(name, filename))
+ } else if (link(realname, filename) && copyfile(name, filename))
goto out_free;
}
@@ -300,6 +301,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
if (symlink(targetname, linkname) == 0)
err = 0;
out_free:
+ free(realname);
free(filename);
free(linkname);
return err;
--
1.7.3.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [tip:perf/urgent] perf buildid-cache: Fix symbolic link handling
2010-12-10 21:06 [PATCH] perf-tools: fix perf-buildid-cache when passing a symbolic link Franck Bui-Huu
@ 2010-12-22 11:28 ` tip-bot for Franck Bui-Huu
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Franck Bui-Huu @ 2010-12-22 11:28 UTC (permalink / raw)
To: linux-tip-commits; +Cc: acme, linux-kernel, hpa, mingo, fbuihuu, tglx
Commit-ID: 68a7a771ad0e2959983729bf88cbc74a7014438f
Gitweb: http://git.kernel.org/tip/68a7a771ad0e2959983729bf88cbc74a7014438f
Author: Franck Bui-Huu <fbuihuu@gmail.com>
AuthorDate: Fri, 10 Dec 2010 22:06:26 +0100
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 16 Dec 2010 09:41:45 -0200
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>
---
| 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 64a85ba..7cba055 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,
const char *name, bool is_kallsyms)
{
const size_t size = PATH_MAX;
- char *filename = malloc(size),
+ char *realname = realpath(name, NULL),
+ *filename = malloc(size),
*linkname = malloc(size), *targetname;
int len, err = -1;
- if (filename == NULL || linkname == NULL)
+ if (realname == NULL || filename == NULL || linkname == NULL)
goto out_free;
len = snprintf(filename, size, "%s%s%s",
- debugdir, is_kallsyms ? "/" : "", name);
+ debugdir, is_kallsyms ? "/" : "", realname);
if (mkdir_p(filename, 0755))
goto out_free;
@@ -283,7 +284,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
if (is_kallsyms) {
if (copyfile("/proc/kallsyms", filename))
goto out_free;
- } else if (link(name, filename) && copyfile(name, filename))
+ } else if (link(realname, filename) && copyfile(name, filename))
goto out_free;
}
@@ -300,6 +301,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
if (symlink(targetname, linkname) == 0)
err = 0;
out_free:
+ free(realname);
free(filename);
free(linkname);
return err;
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-12-22 11:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-10 21:06 [PATCH] perf-tools: fix perf-buildid-cache when passing a symbolic link Franck Bui-Huu
2010-12-22 11:28 ` [tip:perf/urgent] perf buildid-cache: Fix symbolic link handling tip-bot for Franck Bui-Huu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.