X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fkernel.c;h=8e960dfed8fe59786a3de2436aae3155db9851d6;hb=a62a65563c1e7cea740c5f8caf7d425174e2afbe;hp=6264521dee126d7585d1cb721f9ee13227d12457;hpb=6725fe1993a3c70c5fddecf5a458f03b08852edd;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 6264521de..8e960dfed 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -24,11 +24,11 @@ #include #include +#include #include -#include -#include #include "kernel.h" +#include "kern-modules.h" /* * Add context on a kernel channel. @@ -204,12 +204,11 @@ int kernel_create_event(struct lttng_event *ev, } /* - * LTTNG_KERNEL_SYSCALL event creation will return 0 on success. However - * this FD must not be added to the event list. + * LTTNG_KERNEL_SYSCALL event creation will return 0 on success. */ if (ret == 0 && event->event->instrumentation == LTTNG_KERNEL_SYSCALL) { DBG2("Kernel event syscall creation success"); - goto end; + goto add_list; } event->fd = ret; @@ -219,13 +218,13 @@ int kernel_create_event(struct lttng_event *ev, perror("fcntl session fd"); } +add_list: /* Add event to event list */ cds_list_add(&event->list, &channel->events_list.head); channel->event_count++; DBG("Event %s created (fd: %d)", ev->name, event->fd); -end: return 0; free_event: @@ -607,3 +606,66 @@ error_fp: error: return -1; } + +/* + * Get kernel version and validate it. + */ +int kernel_validate_version(int tracer_fd) +{ + int ret; + struct lttng_kernel_tracer_version version; + + ret = kernctl_tracer_version(tracer_fd, &version); + if (ret < 0) { + ERR("Failed at getting the lttng-modules version"); + goto error; + } + + /* Validate version */ + if (version.major != KERN_MODULES_PRE_MAJOR + && version.major != KERN_MODULES_MAJOR) { + goto error_version; + } + + DBG2("Kernel tracer version validated (major version %d)", version.major); + return 0; + +error_version: + ERR("Kernel major version %d is not compatible (supporting <= %d)", + version.major, KERN_MODULES_MAJOR) + ret = -1; + +error: + return ret; +} + +/* + * Kernel work-arounds called at the start of sessiond main(). + */ +int init_kernel_workarounds(void) +{ + int ret; + FILE *fp; + + /* + * boot_id needs to be read once before being used concurrently + * to deal with a Linux kernel race. A fix is proposed for + * upstream, but the work-around is needed for older kernels. + */ + fp = fopen("/proc/sys/kernel/random/boot_id", "r"); + if (!fp) { + goto end_boot_id; + } + while (!feof(fp)) { + char buf[37] = ""; + + ret = fread(buf, 1, sizeof(buf), fp); + if (ret < 0) { + /* Ignore error, we don't really care */ + } + } + fclose(fp); +end_boot_id: + + return 0; +}