Messages in this thread | | | Date | Sun, 12 Jun 2016 12:20:50 +0900 | From | Masami Hiramatsu <> | Subject | Re: [PATCH perf/core v10 09/23] perf probe: Show all cached probes |
| |
On Sat, 11 Jun 2016 09:28:09 +0900 Masami Hiramatsu <mhiramat@kernel.org> wrote:
> On Thu, 9 Jun 2016 11:22:55 -0300 > Arnaldo Carvalho de Melo <acme@kernel.org> wrote: > > > Em Wed, Jun 08, 2016 at 06:30:30PM +0900, Masami Hiramatsu escreveu: > > > +char *build_id_cache__origname(const char *sbuild_id) > > > +{ > > > + char *linkname; > > > + char buf[PATH_MAX]; > > > + char *ret = NULL, *p; > > > + size_t offs = 5; /* == strlen("../..") */ > > > + > > > + linkname = build_id_cache__linkname(sbuild_id, NULL, 0); > > > + if (!linkname) > > > + return NULL; > > > + > > > + if (readlink(linkname, buf, PATH_MAX) < 0) > > > + goto out; > > > + /* The link should be "../..<origpath>/<sbuild_id>" */ > > > + p = strrchr(buf, '/'); /* Cut off the "/<sbuild_id>" */ > > > + if (p && (p > buf + offs)) { > > > + *p = '\0'; > > > + if (buf[offs + 1] == '[') > > > + offs++; /* > > > + * This is a DSO name, like [kernel.kallsyms]. > > > + * Skip the first '/', since this is not the > > > + * cache of a regular file. > > > + */ > > > + ret = strdup(buf + offs); /* Skip "../..[/]" */ > > > > strdup can fail. > > Ah, right.
In this case, build_id_cache__origname() returns ret immediately(see below), so we don't need to take reaction about that :)
> > > + } > > > +out: > > > + free(linkname); > > > + return ret; > > > +}
here, if strdup() fails, this just return NULL. that is OK.
Thanks! -- Masami Hiramatsu <mhiramat@kernel.org>
| |