[lttng-dev] [PATCH lttng-tools 1/2] Override the session.xsd path with an environment variable

David Goulet dgoulet at efficios.com
Mon Apr 14 10:34:58 EDT 2014


On 10 Apr (23:58:02), Jérémie Galarneau wrote:
> The LTTNG_SESSION_CONFIG_XSD_PATH environment variable can be used
> to specify a path which contains the session configuration schema.
> This will allow save-load tests to be ran without installing
> the XSD on the system.
> 
> Signed-off-by: Jérémie Galarneau <jeremie.galarneau at efficios.com>
> ---
>  src/common/config/config.c | 37 ++++++++++++++++++++++++++++++++++++-
>  src/common/defaults.h      |  6 +++---
>  2 files changed, 39 insertions(+), 4 deletions(-)
> 
> diff --git a/src/common/config/config.c b/src/common/config/config.c
> index e61791b..143e6f0 100644
> --- a/src/common/config/config.c
> +++ b/src/common/config/config.c
> @@ -569,12 +569,46 @@ void fini_session_config_validation_ctx(
>  }
>  
>  static
> +char *get_session_config_xsd_path()
> +{
> +	char *xsd_path;
> +	const char *base_path = getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV);
> +	size_t base_path_len;
> +
> +	if (!base_path) {
> +		base_path = DEFAULT_SESSION_CONFIG_XSD_PATH;
> +	}
> +
> +	base_path_len = strlen(base_path);
> +	xsd_path = malloc(base_path_len +
> +		sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME) + 1);
> +	if (!xsd_path) {
> +		goto end;
> +	}
> +
> +	strcpy(xsd_path, base_path);

strncpy() please, I won't accept patches with dangerous libc calls that
should burn in HELL! :P

> +	if (xsd_path[base_path_len - 1] != '/') {
> +		xsd_path[base_path_len++] = '/';
> +	}
> +
> +	strcpy(xsd_path + base_path_len, DEFAULT_SESSION_CONFIG_XSD_FILENAME);

Same.

Cheers!
David

> +end:
> +	return xsd_path;
> +}
> +
> +static
>  int init_session_config_validation_ctx(
>  	struct session_config_validation_ctx *ctx)
>  {
>  	int ret;
> +	char *xsd_path = get_session_config_xsd_path();
> +
> +	if (!xsd_path) {
> +		ret = -LTTNG_ERR_NOMEM;
> +		goto end;
> +	}
>  
> -	ctx->parser_ctx = xmlSchemaNewParserCtxt(DEFAULT_SESSION_CONFIG_XSD_PATH);
> +	ctx->parser_ctx = xmlSchemaNewParserCtxt(xsd_path);
>  	if (!ctx->parser_ctx) {
>  		ERR("XSD parser context creation failed");
>  		ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
> @@ -606,6 +640,7 @@ end:
>  		fini_session_config_validation_ctx(ctx);
>  	}
>  
> +	free(xsd_path);
>  	return ret;
>  }
>  
> diff --git a/src/common/defaults.h b/src/common/defaults.h
> index 7acabf1..de61064 100644
> --- a/src/common/defaults.h
> +++ b/src/common/defaults.h
> @@ -125,9 +125,9 @@
>  #define DEFAULT_SESSION_SYSTEM_CONFIGPATH       DEFAULT_SYSTEM_CONFIGPATH "/" \
>  	DEFAULT_SESSION_PATH
>  #define DEFAULT_SESSION_CONFIG_FILE_EXTENSION   ".lttng"
> -#define DEFAULT_SESSION_CONFIG_XSD_PATH         CONFIG_LTTNG_SYSTEM_DATADIR \
> -	"/xml/lttng/session.xsd"
> -
> +#define DEFAULT_SESSION_CONFIG_XSD_FILENAME     "session.xsd"
> +#define DEFAULT_SESSION_CONFIG_XSD_PATH         CONFIG_LTTNG_SYSTEM_DATADIR "/xml/lttng/"
> +#define DEFAULT_SESSION_CONFIG_XSD_PATH_ENV     "LTTNG_SESSION_CONFIG_XSD_PATH"
>  
>  #define DEFAULT_GLOBAL_APPS_UNIX_SOCK \
>  	DEFAULT_LTTNG_RUNDIR "/" LTTNG_UST_SOCK_FILENAME
> -- 
> 1.9.2
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 603 bytes
Desc: Digital signature
URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20140414/967d40e2/attachment.sig>


More information about the lttng-dev mailing list