Fix: add a kernel context list to the channel
[lttng-tools.git] / src / bin / lttng-sessiond / kernel.c
index 123be4be523d24194309cc93e5c9a52e9fba16c7..b997a4aeab6b7ac0aac7208fa82bacd6e964ce28 100644 (file)
@@ -37,7 +37,7 @@
  * Add context on a kernel channel.
  */
 int kernel_add_channel_context(struct ltt_kernel_channel *chan,
-               struct lttng_kernel_context *ctx)
+               struct ltt_kernel_context *ctx)
 {
        int ret;
 
@@ -45,7 +45,7 @@ int kernel_add_channel_context(struct ltt_kernel_channel *chan,
        assert(ctx);
 
        DBG("Adding context to channel %s", chan->channel->name);
-       ret = kernctl_add_context(chan->fd, ctx);
+       ret = kernctl_add_context(chan->fd, &ctx->ctx);
        if (ret < 0) {
                if (errno != EEXIST) {
                        PERROR("add context ioctl");
@@ -56,13 +56,7 @@ int kernel_add_channel_context(struct ltt_kernel_channel *chan,
                goto error;
        }
 
-       chan->ctx = zmalloc(sizeof(struct lttng_kernel_context));
-       if (chan->ctx == NULL) {
-               PERROR("zmalloc event context");
-               goto error;
-       }
-
-       memcpy(chan->ctx, ctx, sizeof(struct lttng_kernel_context));
+       cds_list_add_tail(&ctx->list, &chan->ctx_list);
 
        return 0;
 
@@ -201,6 +195,9 @@ int kernel_create_event(struct lttng_event *ev,
                case ENOSYS:
                        WARN("Event type not implemented");
                        break;
+               case ENOENT:
+                       WARN("Event %s not found!", ev->name);
+                       break;
                default:
                        PERROR("create event ioctl");
                }
@@ -602,7 +599,7 @@ error:
  */
 ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
 {
-       int fd, pos, ret;
+       int fd, ret;
        char *event;
        size_t nbmem, count = 0;
        FILE *fp;
@@ -634,15 +631,15 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
                goto end;
        }
 
-       while (fscanf(fp, "event { name = %m[^;]; };%n\n", &event, &pos) == 1) {
+       while (fscanf(fp, "event { name = %m[^;]; };\n", &event) == 1) {
                if (count >= nbmem) {
                        struct lttng_event *new_elist;
+                       size_t new_nbmem;
 
-                       DBG("Reallocating event list from %zu to %zu bytes", nbmem,
-                                       nbmem * 2);
-                       /* Double the size */
-                       nbmem <<= 1;
-                       new_elist = realloc(elist, nbmem * sizeof(struct lttng_event));
+                       new_nbmem = nbmem << 1;
+                       DBG("Reallocating event list from %zu to %zu bytes",
+                                       nbmem, new_nbmem);
+                       new_elist = realloc(elist, new_nbmem * sizeof(struct lttng_event));
                        if (new_elist == NULL) {
                                PERROR("realloc list events");
                                free(event);
@@ -650,6 +647,10 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
                                count = -ENOMEM;
                                goto end;
                        }
+                       /* Zero the new memory */
+                       memset(new_elist + nbmem, 0,
+                               (new_nbmem - nbmem) * sizeof(struct lttng_event));
+                       nbmem = new_nbmem;
                        elist = new_elist;
                }
                strncpy(elist[count].name, event, LTTNG_SYMBOL_NAME_LEN);
@@ -755,11 +756,11 @@ void kernel_destroy_session(struct ltt_kernel_session *ksess)
        DBG("Tearing down kernel session");
 
        /*
-        * Destroy channels on the consumer if in no output mode because the
-        * streams are in *no* monitor mode so we have to send a command to clean
-        * them up or else they leaked.
+        * Destroy channels on the consumer if at least one FD has been sent and we
+        * are in no output mode because the streams are in *no* monitor mode so we
+        * have to send a command to clean them up or else they leaked.
         */
-       if (!ksess->output_traces) {
+       if (!ksess->output_traces && ksess->consumer_fds_sent) {
                int ret;
                struct consumer_socket *socket;
                struct lttng_ht_iter iter;
@@ -927,6 +928,8 @@ int kernel_snapshot_record(struct ltt_kernel_session *ksess,
                (void) kernel_consumer_destroy_metadata(socket, ksess->metadata);
        }
 
+       ret = LTTNG_OK;
+
 error_consumer:
        /* Close newly opened metadata stream. It's now on the consumer side. */
        err = close(ksess->metadata_stream_fd);
This page took 0.027692 seconds and 5 git commands to generate.