X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fkernel.c;h=6eeb9b5b1b7824802bb2da554999ca2a46e26bce;hb=8936c33a1a322904bd631caff22358a0bb791cf5;hp=afa5e604fbefff9a9a2465fb5809cfe884d19f60;hpb=db7586006bc1a2b9057a2c108bf1e7d20fd6903f;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index afa5e604f..6eeb9b5b1 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -28,6 +28,7 @@ #include #include "kernel.h" +#include "kern-modules.h" /* * Add context on a kernel channel. @@ -606,3 +607,65 @@ 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.version > KERN_MODULES_VERSION) { + goto error_version; + } + + DBG2("Kernel tracer version validated (major version %d)", version.version); + return 0; + +error_version: + ERR("Kernel major version %d is not compatible (supporting <= %d)", + version.version, KERN_MODULES_VERSION) + 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; +}