Fix: move set base_path of session to URI configuration
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index a17cc678ecab2363a95166b82f1c794a15c8ff96..1dec61ea17b6ba7f74e122e37a7df99afa2e07c6 100644 (file)
@@ -2759,11 +2759,32 @@ int cmd_set_consumer_uri(struct ltt_session *session, size_t nb_uri,
                goto error;
        }
 
+       for (i = 0; i < nb_uri; i++) {
+               if (uris[i].stype != LTTNG_STREAM_CONTROL ||
+                               uris[i].subdir[0] == '\0') {
+                       /* Not interested in these URIs */
+                       continue;
+               }
+
+               if (session->base_path != NULL) {
+                       free(session->base_path);
+                       session->base_path = NULL;
+               }
+
+               /* Set session base_path */
+               session->base_path = strdup(uris[i].subdir);
+               if (!session->base_path) {
+                       PERROR("Copying base path: %s", uris[i].subdir);
+                       goto error;
+               }
+               DBG2("Setting base path for session %" PRIu64 ": %s",
+                               session->id, session->base_path);
+       }
+
        /* Set the "global" consumer URIs */
        for (i = 0; i < nb_uri; i++) {
-               ret = add_uri_to_consumer(session,
-                               session->consumer,
-                               &uris[i], LTTNG_DOMAIN_NONE);
+               ret = add_uri_to_consumer(session, session->consumer, &uris[i],
+                               LTTNG_DOMAIN_NONE);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -2894,7 +2915,6 @@ enum lttng_error_code cmd_create_session_from_descriptor(
        const char *session_name;
        struct ltt_session *new_session = NULL;
        enum lttng_session_descriptor_status descriptor_status;
-       const char *base_path;
 
        session_lock_list();
        if (home_path) {
@@ -2917,13 +2937,9 @@ enum lttng_error_code cmd_create_session_from_descriptor(
                ret_code = LTTNG_ERR_INVALID;
                goto end;
        }
-       ret = lttng_session_descriptor_get_base_path(descriptor, &base_path);
-       if (ret) {
-               ret_code = LTTNG_ERR_INVALID;
-               goto end;
-       }
+
        ret_code = session_create(session_name, creds->uid, creds->gid,
-                       base_path, &new_session);
+                       &new_session);
        if (ret_code != LTTNG_OK) {
                goto end;
        }
@@ -4788,6 +4804,8 @@ int cmd_rotate_session(struct ltt_session *session,
        struct lttng_trace_chunk *chunk_being_archived = NULL;
        struct lttng_trace_chunk *new_trace_chunk = NULL;
        enum lttng_trace_chunk_status chunk_status;
+       bool failed_to_rotate = false;
+       enum lttng_error_code rotation_fail_code = LTTNG_OK;
 
        assert(session);
 
@@ -4845,7 +4863,13 @@ int cmd_rotate_session(struct ltt_session *session,
                }
         }
 
-        /* The current trace chunk becomes the chunk being archived. */
+       /*
+        * The current trace chunk becomes the chunk being archived.
+        *
+        * After this point, "chunk_being_archived" must absolutely
+        * be closed on the consumer(s), otherwise it will never be
+        * cleaned-up, which will result in a leak.
+        */
        ret = session_set_trace_chunk(session, new_trace_chunk,
                        &chunk_being_archived);
        if (ret) {
@@ -4861,13 +4885,15 @@ int cmd_rotate_session(struct ltt_session *session,
        if (session->kernel_session) {
                cmd_ret = kernel_rotate_session(session);
                if (cmd_ret != LTTNG_OK) {
-                       goto error;
+                       failed_to_rotate = true;
+                       rotation_fail_code = cmd_ret;
                }
        }
        if (session->ust_session) {
                cmd_ret = ust_app_rotate_session(session);
                if (cmd_ret != LTTNG_OK) {
-                       goto error;
+                       failed_to_rotate = true;
+                       rotation_fail_code = cmd_ret;
                }
        }
 
@@ -4882,6 +4908,11 @@ int cmd_rotate_session(struct ltt_session *session,
                goto error;
        }
 
+       if (failed_to_rotate) {
+               cmd_ret = rotation_fail_code;
+               goto error;
+       }
+
        session->quiet_rotation = quiet_rotation;
        ret = timer_session_rotation_pending_check_start(session,
                        DEFAULT_ROTATE_PENDING_TIMER);
@@ -4968,7 +4999,7 @@ int cmd_rotate_get_info(struct ltt_session *session,
 
        switch (rotation_state) {
        case LTTNG_ROTATION_STATE_NO_ROTATION:
-               DBG("Reporting that no rotation has occured within the lifetime of session \"%s\"",
+               DBG("Reporting that no rotation has occurred within the lifetime of session \"%s\"",
                                session->name);
                goto end;
        case LTTNG_ROTATION_STATE_EXPIRED:
This page took 0.027272 seconds and 4 git commands to generate.