Fix: list_lttng_agent_events: unbalanced RCU read-side lock on error
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index 2bd010f895c223f83136f1c234f8bead46fbe339..eb5da1b76c44b70dcaf9fa221cb07fef8d2b0cdd 100644 (file)
@@ -510,7 +510,6 @@ static int list_lttng_agent_events(struct agent *agt,
 
        rcu_read_lock();
        nb_event = lttng_ht_get_count(agt->events);
-       rcu_read_unlock();
        if (nb_event == 0) {
                ret = nb_event;
                *total_size = 0;
@@ -524,7 +523,6 @@ static int list_lttng_agent_events(struct agent *agt,
         * This is only valid because the commands which add events are
         * processed in the same thread as the listing.
         */
-       rcu_read_lock();
        cds_lfht_for_each_entry(agt->events->ht, &iter.iter, event, node.node) {
                ret = increment_extended_len(event->filter_expression, NULL, NULL,
                                &extended_len);
@@ -534,7 +532,6 @@ static int list_lttng_agent_events(struct agent *agt,
                        goto error;
                }
        }
-       rcu_read_unlock();
 
        *total_size = nb_event * sizeof(*tmp_events) + extended_len;
        tmp_events = zmalloc(*total_size);
@@ -547,7 +544,6 @@ static int list_lttng_agent_events(struct agent *agt,
        extended_at = ((uint8_t *) tmp_events) +
                nb_event * sizeof(struct lttng_event);
 
-       rcu_read_lock();
        cds_lfht_for_each_entry(agt->events->ht, &iter.iter, event, node.node) {
                strncpy(tmp_events[i].name, event->name, sizeof(tmp_events[i].name));
                tmp_events[i].name[sizeof(tmp_events[i].name) - 1] = '\0';
@@ -816,8 +812,7 @@ end:
        return nb_event;
 
 error:
-       /* Negate the error code to differentiate the size from an error */
-       return -ret;
+       return ret;
 }
 
 /*
@@ -2791,6 +2786,16 @@ int cmd_start_trace(struct ltt_session *session)
                }
        }
 
+       /*
+        * Open a packet in every stream of the session to ensure that viewers
+        * can correctly identify the boundaries of the periods during which
+        * tracing was active for this session.
+        */
+       ret = session_open_packets(session);
+       if (ret != LTTNG_OK) {
+               goto error;
+       }
+
        /*
         * Clear the flag that indicates that a rotation was done while the
         * session was stopped.
@@ -3402,9 +3407,17 @@ int cmd_destroy_session(struct ltt_session *session,
                 */
                ret = cmd_rotate_session(session, NULL, true,
                        LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION);
-               if (ret != LTTNG_OK) {
+               /*
+                * Rotation operations may not be supported by the kernel
+                * tracer. Hence, do not consider this implicit rotation as
+                * a session destruction error. The library has already stopped
+                * the session and waited for pending data; there is nothing
+                * left to do but complete the destruction of the session.
+                */
+               if (ret != LTTNG_OK &&
+                               ret != -LTTNG_ERR_ROTATION_NOT_AVAILABLE_KERNEL) {
                        ERR("Failed to perform a quiet rotation as part of the destruction of session \"%s\": %s",
-                                       session->name, lttng_strerror(-ret));
+                           session->name, lttng_strerror(ret));
                        destruction_last_error = -ret;
                }
        }
@@ -4673,6 +4686,11 @@ enum lttng_error_code snapshot_record(struct ltt_session *session,
                                consumer_copy_output(snapshot_output->consumer);
                strcpy(snapshot_kernel_consumer_output->chunk_path,
                        snapshot_chunk_name);
+
+               /* Copy the original domain subdir. */
+               strcpy(snapshot_kernel_consumer_output->domain_subdir,
+                               original_kernel_consumer_output->domain_subdir);
+
                ret = consumer_copy_sockets(snapshot_kernel_consumer_output,
                                original_kernel_consumer_output);
                if (ret < 0) {
@@ -4695,6 +4713,11 @@ enum lttng_error_code snapshot_record(struct ltt_session *session,
                                consumer_copy_output(snapshot_output->consumer);
                strcpy(snapshot_ust_consumer_output->chunk_path,
                        snapshot_chunk_name);
+
+               /* Copy the original domain subdir. */
+               strcpy(snapshot_ust_consumer_output->domain_subdir,
+                               original_ust_consumer_output->domain_subdir);
+
                ret = consumer_copy_sockets(snapshot_ust_consumer_output,
                                original_ust_consumer_output);
                if (ret < 0) {
This page took 0.025509 seconds and 4 git commands to generate.