[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 15:24:27 EDT 2014
Merged.
David
On 14 Apr (12:10:44), 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 | 40 +++++++++++++++++++++++++++++++++++++++-
> src/common/defaults.h | 6 +++---
> 2 files changed, 42 insertions(+), 4 deletions(-)
>
> diff --git a/src/common/config/config.c b/src/common/config/config.c
> index e61791b..8b34d02 100644
> --- a/src/common/config/config.c
> +++ b/src/common/config/config.c
> @@ -569,12 +569,49 @@ 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;
> + size_t max_path_len;
> +
> + if (!base_path) {
> + base_path = DEFAULT_SESSION_CONFIG_XSD_PATH;
> + }
> +
> + base_path_len = strlen(base_path);
> + max_path_len = base_path_len +
> + sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME) + 1;
> + xsd_path = zmalloc(max_path_len);
> + if (!xsd_path) {
> + goto end;
> + }
> +
> + strncpy(xsd_path, base_path, max_path_len);
> + if (xsd_path[base_path_len - 1] != '/') {
> + xsd_path[base_path_len++] = '/';
> + }
> +
> + strncpy(xsd_path + base_path_len, DEFAULT_SESSION_CONFIG_XSD_FILENAME,
> + max_path_len - base_path_len);
> +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 +643,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/f9f49e7b/attachment-0001.sig>
More information about the lttng-dev
mailing list