Fix: add a kernel context list to the channel
[lttng-tools.git] / src / bin / lttng-sessiond / save.c
index d2bf09208e05b3c4a472657d31ea366b4c22ddba..684c4edbf9c80d5dd3089dde71c6b130772efad8 100644 (file)
@@ -25,7 +25,6 @@
 #include <common/defaults.h>
 #include <common/error.h>
 #include <common/config/config.h>
-#include <common/config/config-session-internal.h>
 #include <common/utils.h>
 #include <common/runas.h>
 #include <lttng/save-internal.h>
@@ -259,8 +258,12 @@ const char *get_ust_context_type_string(
        case LTTNG_UST_CONTEXT_PTHREAD_ID:
                context_type_string = config_event_context_pthread_id;
                break;
+       case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER:
+               context_type_string = config_event_context_perf_thread_counter;
+               break;
        default:
                context_type_string = NULL;
+               break;
        }
 
        return context_type_string;
@@ -667,19 +670,13 @@ int save_kernel_context(struct config_writer *writer,
                goto end;
        }
 
-       ret = config_writer_open_element(writer, config_element_contexts);
-       if (ret) {
-               ret = LTTNG_ERR_SAVE_IO_FAIL;
-               goto end;
-       }
-
        ret = config_writer_open_element(writer, config_element_context);
        if (ret) {
                ret = LTTNG_ERR_SAVE_IO_FAIL;
                goto end;
        }
 
-       if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_COUNTER) {
+       if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER) {
                ret = config_writer_open_element(writer, config_element_perf);
                if (ret) {
                        ret = LTTNG_ERR_SAVE_IO_FAIL;
@@ -738,6 +735,30 @@ int save_kernel_context(struct config_writer *writer,
                goto end;
        }
 
+end:
+       return ret;
+}
+
+static
+int save_kernel_contexts(struct config_writer *writer,
+               struct ltt_kernel_channel *kchan)
+{
+       int ret;
+       struct ltt_kernel_context *ctx;
+
+       ret = config_writer_open_element(writer, config_element_contexts);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       cds_list_for_each_entry(ctx, &kchan->ctx_list, list) {
+               ret = save_kernel_context(writer, &ctx->ctx);
+               if (ret) {
+                       goto end;
+               }
+       }
+
        /* /contexts */
        ret = config_writer_close_element(writer);
        if (ret) {
@@ -845,7 +866,7 @@ int save_kernel_channel(struct config_writer *writer,
                goto end;
        }
 
-       ret = save_kernel_context(writer, kchan->ctx);
+       ret = save_kernel_contexts(writer, kchan);
        if (ret) {
                goto end;
        }
@@ -1398,6 +1419,7 @@ int save_session(struct ltt_session *session,
        struct lttng_save_session_attr *attr, lttng_sock_cred *creds)
 {
        int ret, fd;
+       unsigned int file_opened = 0;   /* Indicate if the file has been opened */
        char config_file_path[PATH_MAX];
        size_t len;
        struct config_writer *writer = NULL;
@@ -1409,6 +1431,7 @@ int save_session(struct ltt_session *session,
        assert(creds);
 
        session_name_len = strlen(session->name);
+       memset(config_file_path, 0, sizeof(config_file_path));
 
        if (!session_access_ok(session,
                LTTNG_SOCK_GET_UID_CRED(creds),
@@ -1419,6 +1442,7 @@ int save_session(struct ltt_session *session,
 
        provided_path = lttng_save_session_attr_get_output_url(attr);
        if (provided_path) {
+               DBG3("Save session in provided path %s", provided_path);
                len = strlen(provided_path);
                if (len >= sizeof(config_file_path)) {
                        ret = LTTNG_ERR_SET_URL;
@@ -1471,9 +1495,12 @@ int save_session(struct ltt_session *session,
        strncpy(config_file_path + len, session->name, session_name_len);
        len += session_name_len;
        strcpy(config_file_path + len, DEFAULT_SESSION_CONFIG_FILE_EXTENSION);
+       len += sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION);
+       config_file_path[len] = '\0';
 
        if (!access(config_file_path, F_OK) && !attr->overwrite) {
-               /* A file with the same name already exists, skip */
+               /* File exists, notify the user since the overwrite flag is off. */
+               ret = LTTNG_ERR_SAVE_FILE_EXIST;
                goto end;
        }
 
@@ -1485,6 +1512,7 @@ int save_session(struct ltt_session *session,
                ret = LTTNG_ERR_SAVE_IO_FAIL;
                goto end;
        }
+       file_opened = 1;
 
        writer = config_writer_create(fd);
        if (!writer) {
@@ -1517,7 +1545,7 @@ int save_session(struct ltt_session *session,
        }
 
        ret = config_writer_write_element_bool(writer, config_element_started,
-                       session->enabled);
+                       session->active);
        if (ret) {
                ret = LTTNG_ERR_SAVE_IO_FAIL;
                goto end;
@@ -1579,7 +1607,7 @@ end:
        }
        if (ret) {
                /* Delete file in case of error */
-               if (unlink(config_file_path)) {
+               if (file_opened && unlink(config_file_path)) {
                        PERROR("Unlinking XML session configuration.");
                }
        }
This page took 0.024601 seconds and 4 git commands to generate.