#include <string.h>
#include <unistd.h>
+#include <common/common.h>
#include <common/kernel-ctl/kernel-ctl.h>
-#include <common/lttngerr.h>
-#include <common/lttng-share.h>
#include "kernel.h"
+#include "kern-modules.h"
/*
* Add context on a kernel channel.
* Init memory size counter
* See kernel-ctl.h for explanation of this value
*/
- nbmem = KERNEL_EVENT_LIST_SIZE;
+ nbmem = KERNEL_EVENT_INIT_LIST_SIZE;
elist = zmalloc(sizeof(struct lttng_event) * nbmem);
while ((size = fscanf(fp, "event { name = %m[^;]; };%n\n", &event, &pos)) == 1) {
- if (count > nbmem) {
+ if (count >= nbmem) {
DBG("Reallocating event list from %zu to %zu bytes", nbmem,
- nbmem + KERNEL_EVENT_LIST_SIZE);
- /* Adding the default size again */
- nbmem += KERNEL_EVENT_LIST_SIZE;
+ nbmem * 2);
+ /* Double the size */
+ nbmem <<= 1;
elist = realloc(elist, nbmem * sizeof(struct lttng_event));
if (elist == NULL) {
perror("realloc list events");
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;
+}