Re: [PATCH v2] trace-cmd: Load trace-cmd plugins from build folder, if exists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2019-04-23 at 12:56 +0300, Tzvetomir Stoyanov wrote:
> [
>  v2 changes:
>   - Removed the logic looking for plugins in the build path.
>   - Added logic which gets the full path of the running trace-cmd
>     binary and loads plugins from "plugins" directory around it, if
> exist.
> ]
> 
> When a development version of trace-cmd is built and run on the
> machine,
> by default it loads all plugins from predefined drierctories :
>   (install_preffix)/lib/traceevent/plugins
>   ~/.traceevent/plugins
>   the path specified in TRACEEVENT_PLUGIN_DIR environment variable.
> Thus, the development plugins will not be loaded. To simplify the
> development
> process, a new logic is added:
>   At plugins load time, check the location of trace-cmd application
> and look
>   for "plugins" directory around it. If found, load plugins from it.
> Those
>   pluigins will be loaded last, so in case of duplication the
> "development"
>   plugins win.
> 
> Signed-off-by: Tzvetomir Stoyanov <tstoyanov@xxxxxxxxxx>
> ---
>  lib/trace-cmd/trace-util.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
> index 8d21fb2..98402a0 100644
> --- a/lib/trace-cmd/trace-util.c
> +++ b/lib/trace-cmd/trace-util.c
> @@ -1364,6 +1364,34 @@ static int add_plugin_file(struct tep_handle
> *pevent, const char *path,
>  	return -ENOMEM;
>  }
>  
> +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.

Cheers,

-- Slavi




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux