From: Jérémie Galarneau Date: Mon, 14 Apr 2014 16:10:44 +0000 (-0400) Subject: Override the session.xsd path with an ENV. variable X-Git-Tag: v2.5.0-rc1~69 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=54e399cbfc6ab1a7ace029acaf02b9c6403366a9;p=lttng-tools.git Override the session.xsd path with an ENV. variable 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 Signed-off-by: David Goulet --- diff --git a/doc/man/lttng-sessiond.8 b/doc/man/lttng-sessiond.8 index 488bf3d29..633cf81f1 100644 --- a/doc/man/lttng-sessiond.8 +++ b/doc/man/lttng-sessiond.8 @@ -148,6 +148,8 @@ value is 5 seconds. Control timeout of socket connection, receive and send. Takes an integer parameter: the timeout value, in milliseconds. A value of 0 or -1 uses the timeout of the operating system (this is the default). +.IP "LTTNG_SESSION_CONFIG_XSD_PATH" +Specify the path that contains the XML session configuration schema (xsd). .SH "SEE ALSO" .PP diff --git a/src/common/config/config.c b/src/common/config/config.c index e61791b7d..8b34d02f1 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -568,13 +568,50 @@ void fini_session_config_validation_ctx( memset(ctx, 0, sizeof(struct 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 7acabf181..de610644c 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