X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fconfig%2Fconfig.c;h=b8a32e6e1f803218e0ba1f0aea10668d865a7dde;hb=b2579dc14eacae00a596d8bb885620c9fa4e263d;hp=0e9e1bdc722661c21fb4172b27ba49a593b742ae;hpb=1114378362fe014288ccaab1d1fed52f7b5703f8;p=lttng-tools.git diff --git a/src/common/config/config.c b/src/common/config/config.c index 0e9e1bdc7..b8a32e6e1 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; } @@ -2267,6 +2305,11 @@ domain_init_error: } } end: + if (ret < 0) { + ERR("Failed to load session %s: %s", name, lttng_strerror(ret)); + lttng_destroy_session(name); + } + free(kernel_domain); free(ust_domain); free(jul_domain); @@ -2344,13 +2387,14 @@ int load_session_from_path(const char *path, const char *session_name, if (!directory) { switch (errno) { case ENOTDIR: - ret = -LTTNG_ERR_LOAD_IO_FAIL; - goto end; + /* Try the file loading. */ + break; case ENOENT: ret = -LTTNG_ERR_LOAD_SESSION_NOENT; goto end; default: - break; + ret = -LTTNG_ERR_LOAD_IO_FAIL; + goto end; } } if (directory) { @@ -2505,5 +2549,12 @@ int config_load_session(const char *path, const char *session_name, } end: fini_session_config_validation_ctx(&validation_ctx); + if (ret == -LTTNG_ERR_LOAD_SESSION_NOENT && !session_name && !path) { + /* + * Don't report an error if no sessions are found when called + * without a session_name or a search path. + */ + ret = 0; + } return ret; }