X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Flttng-live%2Flttng-live.c;h=774b91c8e39926c9bb7ee6c68b4cc53ca61da9a4;hb=f797424a5aa3b965937203073b27d666c25a6987;hp=1ea6073375b15da49b841ab4458fd8375c846518;hpb=961b4173af535c7ffc697520ca754418b859e265;p=babeltrace.git diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index 1ea60733..774b91c8 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -35,6 +35,7 @@ #include #include +#include #include #include "common/assert.h" @@ -274,9 +275,8 @@ void lttng_live_destroy_session(struct lttng_live_session *session) BT_COMP_LOGD("Destroy lttng live session"); if (session->id != -1ULL) { if (lttng_live_detach_session(session)) { - if (session->lttng_live_msg_iter && - !lttng_live_graph_is_canceled( - session->lttng_live_msg_iter)) { + if (!lttng_live_graph_is_canceled( + session->lttng_live_msg_iter)) { /* Old relayd cannot detach sessions. */ BT_COMP_LOGD("Unable to detach lttng live session %" PRIu64, session->id); @@ -442,8 +442,7 @@ enum lttng_live_iterator_status lttng_live_get_session( if (!session->attached) { ret = lttng_live_attach_session(session); if (ret) { - if (lttng_live_msg_iter && lttng_live_graph_is_canceled( - lttng_live_msg_iter)) { + if (lttng_live_graph_is_canceled(lttng_live_msg_iter)) { status = LTTNG_LIVE_ITERATOR_STATUS_AGAIN; } else { status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; @@ -457,13 +456,30 @@ enum lttng_live_iterator_status lttng_live_get_session( status != LTTNG_LIVE_ITERATOR_STATUS_END) { goto end; } - for (trace_idx = 0; trace_idx < session->traces->len; trace_idx++) { + trace_idx = 0; + while (trace_idx < session->traces->len) { struct lttng_live_trace *trace = g_ptr_array_index(session->traces, trace_idx); status = lttng_live_metadata_update(trace); - if (status != LTTNG_LIVE_ITERATOR_STATUS_OK && - status != LTTNG_LIVE_ITERATOR_STATUS_END) { + switch (status) { + case LTTNG_LIVE_ITERATOR_STATUS_OK: + trace_idx++; + break; + case LTTNG_LIVE_ITERATOR_STATUS_END: + /* + * The trace has ended. Remove it of the array an + * continue the iteration. + * We can remove the trace safely when using the + * g_ptr_array_remove_index_fast because it replaces + * the element at trace_idx with the array's last + * element. trace_idx is not incremented because of + * that. + */ + (void) g_ptr_array_remove_index_fast(session->traces, + trace_idx); + break; + default: goto end; } }