On Tue, Apr 23, 2019 at 4:32 PM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote: > > On Tue, 23 Apr 2019 13:10:35 +0000 > Slavomir Kaslev <kaslevs@xxxxxxxxxx> wrote: > > > > > +static char *trace_util_get_source_plugins_dir(void) > > > +{ > > > + char *plugins = "/plugins"; > > > + char path[PATH_MAX+1]; > > > + int slash = 0; > > > + int ret; > > > + > > > + ret = readlink("/proc/self/exe", path, PATH_MAX); > > > + if (ret > PATH_MAX || ret < 0) > > > + return NULL; > > > + > > > + while (ret) { > > > + if ('/' == path[ret--]) > > > + slash++; > > > + if (slash == 2) { > > > + path[ret+1] = 0; > > > + if (strlen(path) + strlen(plugins) > PATH_MAX) > > > + break; > > > + strcat(path, plugins); > > > + return strdup(path); > > > + } > > > + } > > > > Looks good. I think that this while() loop can be simplified using the > > standard library to something like: > > > > char resolved[PATH_MAX+1]; > > > > dirname(path); > > strcat(path, "/../plugins"); > > if (!realpath(path, resolved)) > > return NULL; > > > > The realpath() above is also not strictly necessary. > > Or: > > char *p; > > dirname(path); > p = strrchr(path, '/'); > if (!p) > return NULL; > /* It's only in the source if we are in the tracecmd directory */ > if (strcmp(p, "/tracecmd") != 0) > return NULL; > > strcpy(p, "/plugins"); > > > -- Steve > It makes sense to check for tracecmd directory, though it narrows the use cases. I'll send the next version with this. -- Tzvetomir (Ceco) Stoyanov VMware Open Source Technology Center