X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fkernel.c;h=59d86f45ae1b399866d8656228cedb9c49ce5a37;hp=6b404c0ed97f260d3517d91044315ff8877ec9d7;hb=a5dfbb9db7ba31913657ed921006b13977b7b426;hpb=d069d57732e9a19624078b6e8ca424dbd5827fc0 diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 6b404c0ed..59d86f45a 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -367,6 +367,91 @@ int kernel_disable_syscall(const char *syscall_name, return kernctl_disable_syscall(channel->fd, syscall_name); } +int kernel_track_pid(struct ltt_kernel_session *session, int pid) +{ + DBG("Kernel track PID %d for session id %" PRIu64 ".", + pid, session->id); + return kernctl_track_pid(session->fd, pid); +} + +int kernel_untrack_pid(struct ltt_kernel_session *session, int pid) +{ + DBG("Kernel untrack PID %d for session id %" PRIu64 ".", + pid, session->id); + 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. @@ -853,7 +938,8 @@ void kernel_destroy_channel(struct ltt_kernel_channel *kchan) * 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, uint64_t max_size_per_stream) + struct snapshot_output *output, int wait, + uint64_t nb_packets_per_stream) { int err, ret, saved_metadata_fd; struct consumer_socket *socket; @@ -914,7 +1000,7 @@ int kernel_snapshot_record(struct ltt_kernel_session *ksess, ret = consumer_snapshot_channel(socket, chan->fd, output, 0, ksess->uid, ksess->gid, DEFAULT_KERNEL_TRACE_DIR, wait, - max_size_per_stream); + nb_packets_per_stream); pthread_mutex_unlock(socket->lock); if (ret < 0) { ret = LTTNG_ERR_KERN_CONSUMER_FAIL; @@ -928,7 +1014,7 @@ int kernel_snapshot_record(struct ltt_kernel_session *ksess, pthread_mutex_lock(socket->lock); ret = consumer_snapshot_channel(socket, ksess->metadata->fd, output, 1, ksess->uid, ksess->gid, - DEFAULT_KERNEL_TRACE_DIR, wait, max_size_per_stream); + DEFAULT_KERNEL_TRACE_DIR, wait, 0); pthread_mutex_unlock(socket->lock); if (ret < 0) { ret = LTTNG_ERR_KERN_CONSUMER_FAIL;