X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Fconfig%2Fconfig.c;h=8b34d02f1d54500a339f4cb190d58bba1bf6d4b1;hb=54e399cbfc6ab1a7ace029acaf02b9c6403366a9;hp=04bd2fdf207a71539e4e27a8b26f296b957a4c0b;hpb=a96bc65dd4f5ba299189ccd1aa725f1526429824;p=lttng-tools.git diff --git a/src/common/config/config.c b/src/common/config/config.c index 04bd2fdf2..8b34d02f1 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -569,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; @@ -607,6 +643,7 @@ end: fini_session_config_validation_ctx(ctx); } + free(xsd_path); return ret; } @@ -1187,9 +1224,6 @@ int create_session(const char *name, xmlNodePtr consumer_output_node; assert(name); - assert(kernel_domain); - assert(ust_domain); - assert(jul_domain); if (output_node) { consumer_output_node = xmlFirstElementChild(output_node); @@ -1226,11 +1260,12 @@ int create_session(const char *name, /* network destination */ if (live_timer_interval && live_timer_interval != UINT64_MAX) { - const char *url = output.control_uri ? - output.control_uri : output.data_uri; - - /* URL has to be provided, even if we'll overwrite it after. */ - ret = lttng_create_session_live(name, url, live_timer_interval); + /* + * URLs are provided for sure since the test above make sure that + * with a live timer the data and control URIs are provided. So, + * NULL is passed here and will be set right after. + */ + ret = lttng_create_session_live(name, NULL, live_timer_interval); } else { ret = lttng_create_session(name, NULL); } @@ -2345,7 +2380,14 @@ int load_session_from_path(const char *path, const char *session_name, directory = opendir(path); if (!directory) { - if (errno != ENOTDIR) { + switch (errno) { + case ENOTDIR: + /* Try the file loading. */ + break; + case ENOENT: + ret = -LTTNG_ERR_LOAD_SESSION_NOENT; + goto end; + default: ret = -LTTNG_ERR_LOAD_IO_FAIL; goto end; } @@ -2460,9 +2502,10 @@ int config_load_session(const char *path, const char *session_name, goto end; } - ret = load_session_from_path(path, NULL, + ret = load_session_from_path(path, session_name, &validation_ctx, 0); - if (ret && ret != -LTTNG_ERR_LOAD_SESSION_NOENT) { + if (!ret || (ret && ret != -LTTNG_ERR_LOAD_SESSION_NOENT)) { + /* Session found or an error occured */ free(path); goto end; } @@ -2471,9 +2514,10 @@ int config_load_session(const char *path, const char *session_name, } /* Try system session configuration path */ - ret = load_session_from_path(DEFAULT_SESSION_SYSTEM_CONFIGPATH, NULL, - &validation_ctx, 0); - if (ret && ret != -LTTNG_ERR_LOAD_SESSION_NOENT) { + ret = load_session_from_path(DEFAULT_SESSION_SYSTEM_CONFIGPATH, + session_name, &validation_ctx, 0); + if (!ret || (ret && ret != -LTTNG_ERR_LOAD_SESSION_NOENT)) { + /* Session found or an error occured */ goto end; } } else {