Fix: add missing string msg for save/load error code
[lttng-tools.git] / src / common / config / config.c
index 5e100a7ab6c9c6e66848f5010acc711ffba51b8d..04bd2fdf207a71539e4e27a8b26f296b957a4c0b 100644 (file)
@@ -540,11 +540,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);
@@ -1238,7 +1238,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 +2176,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;
        }
 
@@ -2198,12 +2198,24 @@ int process_session_node(xmlNodePtr session_node, const char *session_name,
 
                switch (domain->type) {
                case LTTNG_DOMAIN_KERNEL:
+                       if (kernel_domain) {
+                               /* Same domain seen twice, invalid! */
+                               goto domain_init_error;
+                       }
                        kernel_domain = domain;
                        break;
                case LTTNG_DOMAIN_UST:
+                       if (ust_domain) {
+                               /* Same domain seen twice, invalid! */
+                               goto domain_init_error;
+                       }
                        ust_domain = domain;
                        break;
                case LTTNG_DOMAIN_JUL:
+                       if (jul_domain) {
+                               /* Same domain seen twice, invalid! */
+                               goto domain_init_error;
+                       }
                        jul_domain = domain;
                        break;
                default:
@@ -2316,7 +2328,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;
 }
@@ -2326,18 +2338,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;
@@ -2354,13 +2367,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;
@@ -2373,6 +2379,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);
@@ -2423,7 +2430,7 @@ end:
        }
 
        if (!session_found) {
-               ret = -LTTNG_ERR_LOAD_SESSION_NOT_FOUND;
+               ret = -LTTNG_ERR_LOAD_SESSION_NOENT;
        }
 
        return ret;
This page took 0.02922 seconds and 5 git commands to generate.