On Tue, Nov 17, 2020 at 01:23:09PM -0800, Ian Rogers wrote:
> On Tue, Nov 17, 2020 at 3:01 AM Jiri Olsa <jo...@kernel.org> wrote:
> 
> > When adding new build id link we fail if the link is already
> > there. Adding check for existing link and output debug message
> > that the build id is already linked.
> >
> > Signed-off-by: Jiri Olsa <jo...@kernel.org>
> > ---
> >  tools/perf/util/build-id.c | 15 ++++++++++++++-
> >  1 file changed, 14 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
> > index 7d9ecc37849c..ef9a31b54ba2 100644
> > --- a/tools/perf/util/build-id.c
> > +++ b/tools/perf/util/build-id.c
> > @@ -754,8 +754,21 @@ int build_id_cache__add_s(const char *sbuild_id,
> > const char *name,
> >         tmp = dir_name + strlen(buildid_dir) - 5;
> >         memcpy(tmp, "../..", 5);
> >
> > -       if (symlink(tmp, linkname) == 0)
> > +       if (symlink(tmp, linkname) == 0) {
> >                 err = 0;
> > +       } else if (errno == EEXIST) {
> > +               char path[PATH_MAX];
> > +
> > +               if (readlink(linkname, path, sizeof(path)) == -1) {
> > +                       pr_err("Cant read link: %s\n", linkname);
> > +                       goto out_free;
> > +               }
> >
> 
> readlink needs null termination, such as:
> https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/perf/util/build-id.c?h=perf/core#n212

will fix, thanks

jirka

> 
> Thanks,
> Ian
> 
> +               if (strcmp(tmp, path)) {
> > +                       pr_debug("build <%s> already linked to %s\n",
> > +                                sbuild_id, linkname);
> > +               }
> > +               err = 0;
> > +       }
> >
> >         /* Update SDT cache : error is just warned */
> >         if (realname &&
> > --
> > 2.26.2
> >
> >

Reply via email to