X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=ltt-sessiond%2Fkernel-ctl.c;h=1abd4cef1e6c242b3451ad940969d7fc964b53de;hp=a4d8099f9f773b1ca485dd8cea6c6d08c635e518;hb=d686b40f66ea5df5ac0b9405991bbc33348b0a88;hpb=540126381ff8f3b1e2b3357329fe105fc0bb5e4c diff --git a/ltt-sessiond/kernel-ctl.c b/ltt-sessiond/kernel-ctl.c index a4d8099f9..1abd4cef1 100644 --- a/ltt-sessiond/kernel-ctl.c +++ b/ltt-sessiond/kernel-ctl.c @@ -123,6 +123,7 @@ int kernel_enable_event(struct ltt_kernel_session *session, char *name) cds_list_for_each_entry(chan, &session->channel_list.head, list) { ret = kernctl_create_event(chan->fd, event->event); if (ret < 0) { + ERR("Unable to enable event %s", name); goto error; } @@ -281,3 +282,63 @@ int kernel_create_metadata_stream(struct ltt_kernel_session *session) error: return -1; } + +/* + * kernel_list_events + * + * Get the event list from the kernel tracer and return that list in the CTF + * format. + */ +ssize_t kernel_list_events(int tracer_fd, char **list) +{ + int fd; + char *buf, *line = NULL; + size_t nb, nbmem, total = 0; + ssize_t size; + FILE *fp; + + fd = kernctl_tracepoint_list(tracer_fd); + if (fd < 0) { + perror("kernel tracepoint list"); + goto error; + } + + fp = fdopen(fd, "r"); + if (fp == NULL) { + perror("kernel tracepoint list fdopen"); + goto error; + } + + /* + * Init memory size counter + * See kernel-ctl.h for explanation of this value + */ + nbmem = KERNEL_EVENT_LIST_SIZE; + buf = malloc(nbmem); + + while ((size = getline(&line, &nb, fp)) != -1) { + if (total + size > nbmem) { + DBG("Reallocating event list from %zd to %zd bytes", nbmem, + total + size + KERNEL_EVENT_LIST_SIZE); + /* Adding the default size again */ + nbmem = total + size + KERNEL_EVENT_LIST_SIZE; + buf = realloc(buf, nbmem); + if (buf == NULL) { + perror("realloc list events"); + goto error; + } + } + memcpy(buf + total, line, size); + total += size; + } + + *list = buf; + + DBG("Kernel list events done"); + + return total; + +error: + return -1; +} +