X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fkernel.c;h=b997a4aeab6b7ac0aac7208fa82bacd6e964ce28;hb=645328ae989e5f50a3a49c1ac34b2fee287a3d7b;hp=ddf01044c816f179b668525c5463c60a6f3483c2;hpb=5c786dedd0156b93984f89ba47ec841277ed7dae;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index ddf01044c..b997a4aea 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -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; @@ -136,11 +130,11 @@ int kernel_create_channel(struct ltt_kernel_session *session, goto error; } - DBG3("Kernel create channel %s with attr: %d, %" PRIu64 ", %" PRIu64 ", %u, %u, %d", + DBG3("Kernel create channel %s with attr: %d, %" PRIu64 ", %" PRIu64 ", %u, %u, %d, %d", chan->name, lkc->channel->attr.overwrite, lkc->channel->attr.subbuf_size, lkc->channel->attr.num_subbuf, lkc->channel->attr.switch_timer_interval, lkc->channel->attr.read_timer_interval, - lkc->channel->attr.output); + lkc->channel->attr.live_timer_interval, lkc->channel->attr.output); /* Kernel tracer channel creation */ ret = kernctl_create_channel(session->fd, &lkc->channel->attr); @@ -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; @@ -819,12 +820,12 @@ void kernel_destroy_channel(struct ltt_kernel_channel *kchan) /* * Take a snapshot for a given kernel session. * - * Return 0 on success or else a negative value. + * Return 0 on success or else return a LTTNG_ERR code. */ int kernel_snapshot_record(struct ltt_kernel_session *ksess, struct snapshot_output *output, int wait, unsigned int nb_streams) { - int ret, saved_metadata_fd; + int err, ret, saved_metadata_fd; struct consumer_socket *socket; struct lttng_ht_iter iter; struct ltt_kernel_metadata *saved_metadata; @@ -863,8 +864,6 @@ int kernel_snapshot_record(struct ltt_kernel_session *ksess, socket, node.node) { struct consumer_output *saved_output; struct ltt_kernel_channel *chan; - /* Code flow error */ - assert(socket->fd >= 0); /* * Temporarly switch consumer output for our snapshot output. As long @@ -892,6 +891,8 @@ int kernel_snapshot_record(struct ltt_kernel_session *ksess, DBG3("Kernel snapshot record maximum stream size %" PRIu64 " is smaller than subbuffer size of %" PRIu64, max_size_per_stream, chan->channel->attr.subbuf_size); + (void) kernel_consumer_destroy_metadata(socket, + ksess->metadata); goto error_consumer; } @@ -903,6 +904,8 @@ int kernel_snapshot_record(struct ltt_kernel_session *ksess, pthread_mutex_unlock(socket->lock); if (ret < 0) { ret = LTTNG_ERR_KERN_CONSUMER_FAIL; + (void) kernel_consumer_destroy_metadata(socket, + ksess->metadata); goto error_consumer; } } @@ -925,10 +928,12 @@ 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. */ - ret = close(ksess->metadata_stream_fd); - if (ret < 0) { + err = close(ksess->metadata_stream_fd); + if (err < 0) { PERROR("close snapshot kernel"); }