syscall tracing: update tests
[lttng-tools.git] / src / bin / lttng-sessiond / trace-kernel.c
index 33e5488ef293fde00f2841094f17d92e15e0a834..ab3282a17f189b9c7b288fab65a5dd224f38fe2b 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #define _GNU_SOURCE
+#define _LGPL_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -38,6 +39,13 @@ struct ltt_kernel_channel *trace_kernel_get_channel_by_name(
        assert(session);
        assert(name);
 
+       /*
+        * If we receive an empty string for channel name, it means the
+        * default channel name is requested.
+        */
+       if (name[0] == '\0')
+               name = DEFAULT_CHANNEL_NAME;
+
        DBG("Trying to find channel %s", name);
 
        cds_list_for_each_entry(chan, &session->channel_list.head, list) {
@@ -54,7 +62,8 @@ struct ltt_kernel_channel *trace_kernel_get_channel_by_name(
  * Find the event name for the given channel.
  */
 struct ltt_kernel_event *trace_kernel_get_event_by_name(
-               char *name, struct ltt_kernel_channel *channel)
+               char *name, struct ltt_kernel_channel *channel,
+               enum lttng_event_type type)
 {
        struct ltt_kernel_event *ev;
 
@@ -62,6 +71,8 @@ struct ltt_kernel_event *trace_kernel_get_event_by_name(
        assert(channel);
 
        cds_list_for_each_entry(ev, &channel->events_list.head, list) {
+               if (type != LTTNG_EVENT_ALL && ev->type != type)
+                       continue;
                if (strcmp(name, ev->event->name) == 0) {
                        DBG("Found event by name %s for channel %s", name,
                                        channel->channel->name);
@@ -144,14 +155,24 @@ struct ltt_kernel_channel *trace_kernel_create_channel(
        }
        memcpy(lkc->channel, chan, sizeof(struct lttng_channel));
 
+       /*
+        * If we receive an empty string for channel name, it means the
+        * default channel name is requested.
+        */
+       if (chan->name[0] == '\0') {
+               strncpy(lkc->channel->name, DEFAULT_CHANNEL_NAME,
+                       sizeof(lkc->channel->name));
+       }
+       lkc->channel->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
+
        lkc->fd = -1;
        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;
 
@@ -159,6 +180,32 @@ 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));
+       }
+
+       CDS_INIT_LIST_HEAD(&kctx->list);
+
+error:
+       return kctx;
+}
+
 /*
  * Allocate and initialize a kernel event. Set name and event type.
  *
@@ -290,7 +337,7 @@ struct ltt_kernel_stream *trace_kernel_create_stream(const char *name,
        }
 
        /* Set name */
-       ret = snprintf(lks->name, sizeof(lks->name), "%s_%d", name, count);
+       ret = snprintf(lks->name, sizeof(lks->name), "%s_%u", name, count);
        if (ret < 0) {
                PERROR("snprintf stream name");
                goto error;
@@ -358,6 +405,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.
  */
@@ -365,6 +423,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);
@@ -388,11 +447,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.025908 seconds and 5 git commands to generate.