Fix: add a kernel context list to the channel
[lttng-tools.git] / src / bin / lttng-sessiond / trace-kernel.c
index 363d010a1a2aed47213e51ae240ed3a00fd5d460..8e074fd91b0dcbe829f8c053d32ac6e92766d32c 100644 (file)
@@ -165,10 +165,10 @@ struct ltt_kernel_channel *trace_kernel_create_channel(
        lkc->stream_count = 0;
        lkc->event_count = 0;
        lkc->enabled = 1;
-       lkc->ctx = NULL;
        /* Init linked list */
        CDS_INIT_LIST_HEAD(&lkc->events_list.head);
        CDS_INIT_LIST_HEAD(&lkc->stream_list.head);
+       CDS_INIT_LIST_HEAD(&lkc->ctx_list);
 
        return lkc;
 
@@ -176,6 +176,30 @@ error:
        return NULL;
 }
 
+/*
+ * Allocate and init a kernel context object.
+ *
+ * Return the allocated object or NULL on error.
+ */
+struct ltt_kernel_context *trace_kernel_create_context(
+               struct lttng_kernel_context *ctx)
+{
+       struct ltt_kernel_context *kctx;
+
+       kctx = zmalloc(sizeof(*kctx));
+       if (!kctx) {
+               PERROR("zmalloc kernel context");
+               goto error;
+       }
+
+       if (ctx) {
+               memcpy(&kctx->ctx, ctx, sizeof(kctx->ctx));
+       }
+
+error:
+       return kctx;
+}
+
 /*
  * Allocate and initialize a kernel event. Set name and event type.
  *
@@ -375,6 +399,17 @@ void trace_kernel_destroy_event(struct ltt_kernel_event *event)
        free(event);
 }
 
+/*
+ * Cleanup kernel context structure.
+ */
+void trace_kernel_destroy_context(struct ltt_kernel_context *ctx)
+{
+       assert(ctx);
+
+       cds_list_del(&ctx->list);
+       free(ctx);
+}
+
 /*
  * Cleanup kernel channel structure.
  */
@@ -382,6 +417,7 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel)
 {
        struct ltt_kernel_stream *stream, *stmp;
        struct ltt_kernel_event *event, *etmp;
+       struct ltt_kernel_context *ctx, *ctmp;
        int ret;
 
        assert(channel);
@@ -405,11 +441,15 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel)
                trace_kernel_destroy_event(event);
        }
 
+       /* For each context in the channel list */
+       cds_list_for_each_entry_safe(ctx, ctmp, &channel->ctx_list, list) {
+               trace_kernel_destroy_context(ctx);
+       }
+
        /* Remove from channel list */
        cds_list_del(&channel->list);
 
        free(channel->channel);
-       free(channel->ctx);
        free(channel);
 }
 
This page took 0.02631 seconds and 5 git commands to generate.