X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Fconfig%2Fconfig.c;h=7c6c49b6661a5b7353b0b2aecf67926938a5bdb6;hb=883d970a45de63864c1b2ae956fc01e835e351c4;hp=4eaa274e82ce9e24d7f06d29c0c73ba8a80793d4;hpb=c33e6729ebef69f69a239dd7aee61e802ea29ab6;p=lttng-tools.git diff --git a/src/common/config/config.c b/src/common/config/config.c index 4eaa274e8..7c6c49b66 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -540,11 +539,11 @@ void xml_error_handler(void *ctx, const char *format, ...) va_start(args, format); ret = vasprintf(&errMsg, format, args); + va_end(args); if (ret == -1) { ERR("String allocation failed in xml error handler"); return; } - va_end(args); fprintf(stderr, "XML Error: %s", errMsg); free(errMsg); @@ -1187,9 +1186,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); @@ -1238,7 +1234,7 @@ int create_session(const char *name, goto end; } - for (i = 0; i < (sizeof(domains) / sizeof(*domain)); i++) { + for (i = 0; i < (sizeof(domains) / sizeof(domains[0])); i++) { domain = domains[i]; if (!domain) { continue; @@ -2176,7 +2172,7 @@ int process_session_node(xmlNodePtr session_node, const char *session_name, if (session_name && strcmp(name, session_name)) { /* This is not the session we are looking for */ - ret = -LTTNG_ERR_LOAD_SESSION_NOT_FOUND; + ret = -LTTNG_ERR_LOAD_SESSION_NOENT; goto end; } @@ -2328,7 +2324,7 @@ int load_session_from_file(const char *path, const char *session_name, end: xmlFreeDoc(doc); if (!ret) { - ret = session_found ? 0 : -LTTNG_ERR_LOAD_SESSION_NOT_FOUND; + ret = session_found ? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT; } return ret; } @@ -2338,18 +2334,19 @@ int load_session_from_path(const char *path, const char *session_name, struct session_config_validation_ctx *validation_ctx, int override) { int ret, session_found = !session_name; - struct stat sb; DIR *directory = NULL; assert(path); assert(validation_ctx); - ret = stat(path, &sb); - if (ret) { - ret = -LTTNG_ERR_LOAD_SESSION_NOENT; - goto end; + directory = opendir(path); + if (!directory) { + if (errno != ENOTDIR) { + ret = -LTTNG_ERR_LOAD_IO_FAIL; + goto end; + } } - if (S_ISDIR(sb.st_mode)) { + if (directory) { struct dirent *entry; struct dirent *result; char *file_path = NULL; @@ -2366,13 +2363,6 @@ int load_session_from_path(const char *path, const char *session_name, goto end; } - directory = opendir(path); - if (!directory) { - ret = -LTTNG_ERR_LOAD_IO_FAIL; - free(entry); - goto end; - } - file_path = zmalloc(PATH_MAX); if (!file_path) { ret = -LTTNG_ERR_NOMEM; @@ -2385,6 +2375,7 @@ int load_session_from_path(const char *path, const char *session_name, file_path[path_len++] = '/'; } + ret = 0; /* Search for *.lttng files */ while (!readdir_r(directory, entry, &result) && result) { size_t file_name_len = strlen(result->d_name); @@ -2435,7 +2426,7 @@ end: } if (!session_found) { - ret = -LTTNG_ERR_LOAD_SESSION_NOT_FOUND; + ret = -LTTNG_ERR_LOAD_SESSION_NOENT; } return ret; @@ -2465,7 +2456,7 @@ 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) { free(path); @@ -2476,8 +2467,8 @@ 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); + ret = load_session_from_path(DEFAULT_SESSION_SYSTEM_CONFIGPATH, + session_name, &validation_ctx, 0); if (ret && ret != -LTTNG_ERR_LOAD_SESSION_NOENT) { goto end; }