Tests: add missing kernel test cases to make check target
[lttng-tools.git] / src / bin / lttng-sessiond / modprobe.cpp
1 /*
2 * Copyright (C) 2011 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2014 Jan Glauber <jan.glauber@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 /**
10 * @file modprobe.c
11 *
12 * @brief modprobe related functions.
13 *
14 */
15
16 #define _LGPL_SOURCE
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <sys/wait.h>
20
21 #include <common/common.h>
22 #include <common/utils.h>
23
24 #include "modprobe.h"
25 #include "kern-modules.h"
26 #include "lttng-sessiond.h"
27
28 /* LTTng kernel tracer mandatory core modules list */
29 struct kern_modules_param kern_modules_control_core[] = {
30 {
31 .name = (char *) "lttng-ring-buffer-client-discard",
32 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED,
33 },
34 {
35 .name = (char *) "lttng-ring-buffer-client-overwrite",
36 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED,
37 },
38 {
39 .name = (char *) "lttng-ring-buffer-metadata-client",
40 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED,
41 },
42 {
43 .name = (char *) "lttng-ring-buffer-client-mmap-discard",
44 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED,
45 },
46 {
47 .name = (char *) "lttng-ring-buffer-client-mmap-overwrite",
48 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED,
49 },
50 {
51 .name = (char *) "lttng-ring-buffer-metadata-mmap-client",
52 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED,
53 },
54 {
55 .name = (char *) "lttng-ring-buffer-event_notifier-client",
56 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
57 },
58 {
59 .name = (char *) "lttng-counter-client-percpu-64-modular",
60 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
61 },
62 {
63 .name = (char *) "lttng-counter-client-percpu-32-modular",
64 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
65 },
66 };
67
68 /* LTTng kerneltracer probe modules list */
69 struct kern_modules_param kern_modules_probes_default[] = {
70 {
71 .name = (char *) "lttng-probe-asoc",
72 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
73 },
74 {
75 .name = (char *) "lttng-probe-block",
76 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
77 },
78 {
79 .name = (char *) "lttng-probe-btrfs",
80 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
81 },
82 {
83 .name = (char *) "lttng-probe-compaction",
84 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
85 },
86 {
87 .name = (char *) "lttng-probe-ext3",
88 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
89 },
90 {
91 .name = (char *) "lttng-probe-ext4",
92 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
93 },
94 {
95 .name = (char *) "lttng-probe-gpio",
96 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
97 },
98 {
99 .name = (char *) "lttng-probe-i2c",
100 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
101 },
102 {
103 .name = (char *) "lttng-probe-irq",
104 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
105 },
106 {
107 .name = (char *) "lttng-probe-jbd",
108 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
109 },
110 {
111 .name = (char *) "lttng-probe-jbd2",
112 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
113 },
114 {
115 .name = (char *) "lttng-probe-kmem",
116 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
117 },
118 {
119 .name = (char *) "lttng-probe-kvm",
120 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
121 },
122 {
123 .name = (char *) "lttng-probe-kvm-x86",
124 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
125 },
126 {
127 .name = (char *) "lttng-probe-kvm-x86-mmu",
128 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
129 },
130 {
131 .name = (char *) "lttng-probe-lock",
132 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
133 },
134 {
135 .name = (char *) "lttng-probe-module",
136 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
137 },
138 {
139 .name = (char *) "lttng-probe-napi",
140 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
141 },
142 {
143 .name = (char *) "lttng-probe-net",
144 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
145 },
146 {
147 .name = (char *) "lttng-probe-power",
148 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
149 },
150 {
151 .name = (char *) "lttng-probe-preemptirq",
152 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
153 },
154 {
155 .name = (char *) "lttng-probe-printk",
156 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
157 },
158 {
159 .name = (char *) "lttng-probe-random",
160 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
161 },
162 {
163 .name = (char *) "lttng-probe-rcu",
164 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
165 },
166 {
167 .name = (char *) "lttng-probe-regmap",
168 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
169 },
170 {
171 .name = (char *) "lttng-probe-regulator",
172 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
173 },
174 {
175 .name = (char *) "lttng-probe-rpm",
176 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
177 },
178 {
179 .name = (char *) "lttng-probe-sched",
180 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
181 },
182 {
183 .name = (char *) "lttng-probe-scsi",
184 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
185 },
186 {
187 .name = (char *) "lttng-probe-signal",
188 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
189 },
190 {
191 .name = (char *) "lttng-probe-skb",
192 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
193 },
194 {
195 .name = (char *) "lttng-probe-sock",
196 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
197 },
198 {
199 .name = (char *) "lttng-probe-statedump",
200 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
201 },
202 {
203 .name = (char *) "lttng-probe-sunrpc",
204 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
205 },
206 {
207 .name = (char *) "lttng-probe-timer",
208 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
209 },
210 {
211 .name = (char *) "lttng-probe-udp",
212 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
213 },
214 {
215 .name = (char *) "lttng-probe-vmscan",
216 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
217 },
218 {
219 .name = (char *) "lttng-probe-v4l2",
220 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
221 },
222 {
223 .name = (char *) "lttng-probe-workqueue",
224 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
225 },
226 {
227 .name = (char *) "lttng-probe-writeback",
228 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
229 },
230 {
231 .name = (char *) "lttng-probe-x86-irq-vectors",
232 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
233 },
234 {
235 .name = (char *) "lttng-probe-x86-exceptions",
236 .load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL,
237 },
238 };
239
240 /* dynamic probe modules list */
241 static struct kern_modules_param *probes;
242 static int nr_probes;
243 static int probes_capacity;
244
245 #if HAVE_KMOD
246 #include <libkmod.h>
247
248 /**
249 * @brief Logging function for libkmod integration.
250 */
251 static ATTR_FORMAT_PRINTF(6, 0)
252 void log_kmod(void *data, int priority, const char *file, int line,
253 const char *fn, const char *format, va_list args)
254 {
255 char *str;
256
257 if (vasprintf(&str, format, args) < 0) {
258 return;
259 }
260
261 DBG("libkmod: %s", str);
262 free(str);
263 }
264
265 /**
266 * @brief Setup the libkmod context.
267 *
268 * Create the context, add a custom logging function and preload the
269 * ressources for faster operation.
270 *
271 * @returns \c 0 on success
272 * \c < 0 on error
273 */
274 static int setup_kmod_ctx(struct kmod_ctx **ctx)
275 {
276 int ret = 0;
277
278 *ctx = kmod_new(NULL, NULL);
279 if (!ctx) {
280 PERROR("Unable to create kmod library context");
281 ret = -ENOMEM;
282 goto error;
283 }
284
285 /*
286 * Parameter 2 of kmod_set_log_fn generates a
287 * -Wsuggest-attribute=formatkmod_set_log_fn warning that we can't fix,
288 * ignore it.
289 */
290 DIAGNOSTIC_PUSH
291 DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT
292 kmod_set_log_fn(*ctx, log_kmod, NULL);
293 DIAGNOSTIC_POP
294 ret = kmod_load_resources(*ctx);
295 if (ret < 0) {
296 ERR("Failed to load kmod library resources");
297 goto error;
298 }
299
300 error:
301 return ret;
302 }
303
304 /**
305 * @brief Loads the kernel modules in \p modules
306 *
307 * @param modules List of modules to load
308 * @param entries Number of modules in the list
309 *
310 * If the modules are required, we will return with error after the
311 * first failed module load, otherwise we continue loading.
312 *
313 * @returns \c 0 on success
314 * \c < 0 on error
315 */
316 static int modprobe_lttng(struct kern_modules_param *modules,
317 int entries)
318 {
319 int ret = 0, i;
320 struct kmod_ctx *ctx;
321
322 ret = setup_kmod_ctx(&ctx);
323 if (ret < 0) {
324 goto error;
325 }
326
327 for (i = 0; i < entries; i++) {
328 struct kmod_module *mod = NULL;
329
330 ret = kmod_module_new_from_name(ctx, modules[i].name, &mod);
331 if (ret < 0) {
332 PERROR("Failed to create kmod module for %s", modules[i].name);
333 goto error;
334 }
335
336 ret = kmod_module_probe_insert_module(mod, 0,
337 NULL, NULL, NULL, NULL);
338 if (ret == -EEXIST) {
339 DBG("Module %s is already loaded", modules[i].name);
340 ret = 0;
341 } else if (ret < 0) {
342 if (modules[i].load_policy == KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED) {
343 ERR("Unable to load required module %s",
344 modules[i].name);
345 goto error;
346 } else {
347 DBG("Unable to load optional module %s; continuing",
348 modules[i].name);
349 ret = 0;
350 }
351 } else {
352 DBG("Modprobe successfully %s", modules[i].name);
353 modules[i].loaded = true;
354 }
355
356 kmod_module_unref(mod);
357 }
358
359 error:
360 if (ctx) {
361 kmod_unref(ctx);
362 }
363 return ret;
364 }
365
366 /**
367 * @brief Recursively unload modules.
368 *
369 * This function implements the same modules unloading behavior as
370 * 'modprobe -r' or rmmod, it will recursevily go trought the \p module
371 * dependencies and unload modules with a refcount of 0.
372 *
373 * @param mod The module to unload
374 *
375 * @returns \c 0 on success
376 * \c < 0 on error
377 */
378 static int rmmod_recurse(struct kmod_module *mod) {
379 int ret = 0;
380 struct kmod_list *deps, *itr;
381
382 if (kmod_module_get_initstate(mod) == KMOD_MODULE_BUILTIN) {
383 DBG("Module %s is builtin", kmod_module_get_name(mod));
384 return ret;
385 }
386
387 ret = kmod_module_remove_module(mod, 0);
388
389 deps = kmod_module_get_dependencies(mod);
390 if (deps != NULL) {
391 kmod_list_foreach(itr, deps) {
392 struct kmod_module *dep = kmod_module_get_module(itr);
393 if (kmod_module_get_refcnt(dep) == 0) {
394 DBG("Recursive remove module %s",
395 kmod_module_get_name(dep));
396 rmmod_recurse(dep);
397 }
398 kmod_module_unref(dep);
399 }
400 kmod_module_unref_list(deps);
401 }
402
403 return ret;
404 }
405
406 /**
407 * @brief Unloads the kernel modules in \p modules
408 *
409 * @param modules List of modules to unload
410 * @param entries Number of modules in the list
411 *
412 */
413 static void modprobe_remove_lttng(const struct kern_modules_param *modules,
414 int entries)
415 {
416 int ret = 0, i;
417 struct kmod_ctx *ctx;
418
419 ret = setup_kmod_ctx(&ctx);
420 if (ret < 0) {
421 goto error;
422 }
423
424 for (i = entries - 1; i >= 0; i--) {
425 struct kmod_module *mod = NULL;
426
427 if (!modules[i].loaded) {
428 continue;
429 }
430
431 ret = kmod_module_new_from_name(ctx, modules[i].name, &mod);
432 if (ret < 0) {
433 PERROR("Failed to create kmod module for %s", modules[i].name);
434 goto error;
435 }
436
437 ret = rmmod_recurse(mod);
438 if (ret == -EEXIST) {
439 DBG("Module %s is not in kernel.", modules[i].name);
440 } else if (modules[i].load_policy == KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED && ret < 0) {
441 ERR("Unable to remove module %s", modules[i].name);
442 } else {
443 DBG("Modprobe removal successful %s",
444 modules[i].name);
445 }
446
447 kmod_module_unref(mod);
448 }
449
450 error:
451 if (ctx) {
452 kmod_unref(ctx);
453 }
454 }
455
456 #else /* HAVE_KMOD */
457
458 static int modprobe_lttng(struct kern_modules_param *modules,
459 int entries)
460 {
461 int ret = 0, i;
462 char modprobe[256];
463
464 for (i = 0; i < entries; i++) {
465 ret = snprintf(modprobe, sizeof(modprobe),
466 "/sbin/modprobe %s%s",
467 modules[i].load_policy == KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED ? "" : "-q ",
468 modules[i].name);
469 if (ret < 0) {
470 PERROR("snprintf modprobe");
471 goto error;
472 }
473 modprobe[sizeof(modprobe) - 1] = '\0';
474 ret = system(modprobe);
475 if (ret == -1) {
476 if (modules[i].load_policy == KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED) {
477 ERR("Unable to launch modprobe for required module %s",
478 modules[i].name);
479 goto error;
480 } else {
481 DBG("Unable to launch modprobe for optional module %s; continuing",
482 modules[i].name);
483 ret = 0;
484 }
485 } else if (WEXITSTATUS(ret) != 0) {
486 if (modules[i].load_policy == KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED) {
487 ERR("Unable to load required module %s",
488 modules[i].name);
489 goto error;
490 } else {
491 DBG("Unable to load optional module %s; continuing",
492 modules[i].name);
493 ret = 0;
494 }
495 } else {
496 DBG("Modprobe successfully %s", modules[i].name);
497 modules[i].loaded = true;
498 }
499 }
500
501 error:
502 return ret;
503 }
504
505 static void modprobe_remove_lttng(const struct kern_modules_param *modules,
506 int entries)
507 {
508 int ret = 0, i;
509 char modprobe[256];
510
511 for (i = entries - 1; i >= 0; i--) {
512 if (!modules[i].loaded) {
513 continue;
514 }
515 ret = snprintf(modprobe, sizeof(modprobe),
516 "/sbin/modprobe -r -q %s",
517 modules[i].name);
518 if (ret < 0) {
519 PERROR("snprintf modprobe -r");
520 return;
521 }
522 modprobe[sizeof(modprobe) - 1] = '\0';
523 ret = system(modprobe);
524 if (ret == -1) {
525 if (modules[i].load_policy == KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED) {
526 ERR("Unable to launch modprobe -r for required module %s",
527 modules[i].name);
528 } else {
529 DBG("Unable to launch modprobe -r for optional module %s",
530 modules[i].name);
531 }
532 } else if (WEXITSTATUS(ret) != 0) {
533 if (modules[i].load_policy == KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED) {
534 ERR("Unable to remove required module %s",
535 modules[i].name);
536 } else {
537 DBG("Unable to remove optional module %s",
538 modules[i].name);
539 }
540 } else {
541 DBG("Modprobe removal successful %s", modules[i].name);
542 }
543 }
544 }
545
546 #endif /* HAVE_KMOD */
547
548 /*
549 * Remove control kernel module(s) in reverse load order.
550 */
551 void modprobe_remove_lttng_control(void)
552 {
553 modprobe_remove_lttng(kern_modules_control_core,
554 ARRAY_SIZE(kern_modules_control_core));
555 }
556
557 static void free_probes(void)
558 {
559 int i;
560
561 if (!probes) {
562 return;
563 }
564 for (i = 0; i < nr_probes; ++i) {
565 free(probes[i].name);
566 }
567 free(probes);
568 probes = NULL;
569 nr_probes = 0;
570 }
571
572 /*
573 * Remove data kernel modules in reverse load order.
574 */
575 void modprobe_remove_lttng_data(void)
576 {
577 if (!probes) {
578 return;
579 }
580
581 modprobe_remove_lttng(probes, nr_probes);
582 free_probes();
583 }
584
585 /*
586 * Remove all kernel modules in reverse order.
587 */
588 void modprobe_remove_lttng_all(void)
589 {
590 modprobe_remove_lttng_data();
591 modprobe_remove_lttng_control();
592 }
593
594 /*
595 * Load control kernel module(s).
596 */
597 int modprobe_lttng_control(void)
598 {
599 return modprobe_lttng(kern_modules_control_core,
600 ARRAY_SIZE(kern_modules_control_core));
601 }
602
603 /**
604 * Grow global list of probes (double capacity or set it to 1 if
605 * currently 0 and copy existing data).
606 */
607 static int grow_probes(void)
608 {
609 int i;
610 struct kern_modules_param *tmp_probes;
611
612 /* Initialize capacity to 1 if 0. */
613 if (probes_capacity == 0) {
614 probes = (kern_modules_param *) zmalloc(sizeof(*probes));
615 if (!probes) {
616 PERROR("malloc probe list");
617 return -ENOMEM;
618 }
619
620 probes_capacity = 1;
621 return 0;
622 }
623
624 /* Double size. */
625 probes_capacity *= 2;
626
627 tmp_probes = (kern_modules_param *) zmalloc(sizeof(*tmp_probes) * probes_capacity);
628 if (!tmp_probes) {
629 PERROR("malloc probe list");
630 return -ENOMEM;
631 }
632
633 for (i = 0; i < nr_probes; ++i) {
634 /* Ownership of 'name' field is transferred. */
635 tmp_probes[i] = probes[i];
636 }
637
638 /* Replace probes with larger copy. */
639 free(probes);
640 probes = tmp_probes;
641
642 return 0;
643 }
644
645 /*
646 * Appends a comma-separated list of probes to the global list
647 * of probes.
648 */
649 static int append_list_to_probes(const char *list)
650 {
651 char *next;
652 int ret;
653 char *tmp_list, *cur_list, *saveptr;
654
655 LTTNG_ASSERT(list);
656
657 cur_list = tmp_list = strdup(list);
658 if (!tmp_list) {
659 PERROR("strdup temp list");
660 return -ENOMEM;
661 }
662
663 for (;;) {
664 size_t name_len;
665 struct kern_modules_param *cur_mod;
666
667 next = strtok_r(cur_list, ",", &saveptr);
668 if (!next) {
669 break;
670 }
671 cur_list = NULL;
672
673 /* filter leading spaces */
674 while (*next == ' ') {
675 next++;
676 }
677
678 if (probes_capacity <= nr_probes) {
679 ret = grow_probes();
680 if (ret) {
681 goto error;
682 }
683 }
684
685 /* Length 13 is "lttng-probe-" + \0 */
686 name_len = strlen(next) + 13;
687
688 cur_mod = &probes[nr_probes];
689 cur_mod->name = (char *) zmalloc(name_len);
690 if (!cur_mod->name) {
691 PERROR("malloc probe list");
692 ret = -ENOMEM;
693 goto error;
694 }
695
696 ret = snprintf(cur_mod->name, name_len, "lttng-probe-%s", next);
697 if (ret < 0) {
698 PERROR("snprintf modprobe name");
699 ret = -ENOMEM;
700 goto error;
701 }
702
703 cur_mod->load_policy = KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL;
704
705 nr_probes++;
706 }
707
708 free(tmp_list);
709 return 0;
710
711 error:
712 free(tmp_list);
713 free_probes();
714 return ret;
715 }
716
717 /*
718 * Load data kernel module(s).
719 */
720 int modprobe_lttng_data(void)
721 {
722 int ret, i;
723 char *list;
724
725 /*
726 * Base probes: either from command line option, environment
727 * variable or default list.
728 */
729 list = the_config.kmod_probes_list.value;
730 if (list) {
731 /* User-specified probes. */
732 ret = append_list_to_probes(list);
733 if (ret) {
734 return ret;
735 }
736 } else {
737 /* Default probes. */
738 int def_len = ARRAY_SIZE(kern_modules_probes_default);
739
740 probes = (kern_modules_param *) zmalloc(sizeof(*probes) * def_len);
741 if (!probes) {
742 PERROR("malloc probe list");
743 return -ENOMEM;
744 }
745
746 nr_probes = probes_capacity = def_len;
747
748 for (i = 0; i < def_len; ++i) {
749 char* name = strdup(kern_modules_probes_default[i].name);
750
751 if (!name) {
752 PERROR("strdup probe item");
753 ret = -ENOMEM;
754 goto error;
755 }
756
757 probes[i].name = name;
758 probes[i].load_policy = kern_modules_probes_default[i].load_policy;
759 }
760 }
761
762 /*
763 * Extra modules? Append them to current probes list.
764 */
765 list = the_config.kmod_extra_probes_list.value;
766 if (list) {
767 ret = append_list_to_probes(list);
768 if (ret) {
769 goto error;
770 }
771 }
772
773 /*
774 * Load probes modules now.
775 */
776 ret = modprobe_lttng(probes, nr_probes);
777 if (ret) {
778 goto error;
779 }
780 return ret;
781
782 error:
783 free_probes();
784 return ret;
785 }
This page took 0.048299 seconds and 4 git commands to generate.