X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fkernel.c;h=59d86f45ae1b399866d8656228cedb9c49ce5a37;hp=4bb418949d3ea330b60397ed2352f5541c7fcbdc;hb=a5dfbb9db7ba31913657ed921006b13977b7b426;hpb=a9ad0c8fb50ac8cf9e9812dd9c9b4f949bac19a8 diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 4bb418949..59d86f45a 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -381,6 +381,77 @@ int kernel_untrack_pid(struct ltt_kernel_session *session, int pid) return kernctl_untrack_pid(session->fd, pid); } +ssize_t kernel_list_tracker_pids(struct ltt_kernel_session *session, + int **_pids) +{ + int fd, ret; + int pid; + ssize_t nbmem, count = 0; + FILE *fp; + int *pids; + + fd = kernctl_list_tracker_pids(session->fd); + if (fd < 0) { + PERROR("kernel tracker pids list"); + goto error; + } + + fp = fdopen(fd, "r"); + if (fp == NULL) { + PERROR("kernel tracker pids list fdopen"); + goto error_fp; + } + + nbmem = KERNEL_TRACKER_PIDS_INIT_LIST_SIZE; + pids = zmalloc(sizeof(*pids) * nbmem); + if (pids == NULL) { + PERROR("alloc list pids"); + count = -ENOMEM; + goto end; + } + + while (fscanf(fp, "process { pid = %u; };\n", &pid) == 1) { + if (count >= nbmem) { + int *new_pids; + size_t new_nbmem; + + new_nbmem = nbmem << 1; + DBG("Reallocating pids list from %zu to %zu entries", + nbmem, new_nbmem); + new_pids = realloc(pids, new_nbmem * sizeof(*new_pids)); + if (new_pids == NULL) { + PERROR("realloc list events"); + free(pids); + count = -ENOMEM; + goto end; + } + /* Zero the new memory */ + memset(new_pids + nbmem, 0, + (new_nbmem - nbmem) * sizeof(*new_pids)); + nbmem = new_nbmem; + pids = new_pids; + } + pids[count++] = pid; + } + + *_pids = pids; + DBG("Kernel list tracker pids done (%zd pids)", count); +end: + ret = fclose(fp); /* closes both fp and fd */ + if (ret) { + PERROR("fclose"); + } + return count; + +error_fp: + ret = close(fd); + if (ret) { + PERROR("close"); + } +error: + return -1; +} + /* * Create kernel metadata, open from the kernel tracer and add it to the * kernel session.