Cleanup: sessiond modprobe.c: coding style
[lttng-tools.git] / src / bin / lttng-sessiond / modprobe.c
index d329bb9514905570a1c3a25c36c5a9672d4bf353..b5b9d8cb793c2d6bbffc156d0ea8f6d314a4b0c7 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #define _GNU_SOURCE
+#define _LGPL_SOURCE
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -98,8 +99,8 @@ static struct kern_modules_param *probes;
 static int nr_probes;
 static int probes_capacity;
 
-void modprobe_remove_lttng(const struct kern_modules_param *modules,
-                          int entries, int required)
+static void modprobe_remove_lttng(const struct kern_modules_param *modules,
+               int entries, int required)
 {
        int ret = 0, i;
        char modprobe[256];
@@ -209,8 +210,16 @@ static int modprobe_lttng(struct kern_modules_param *modules,
 
                ret = kmod_module_probe_insert_module(mod, KMOD_PROBE_IGNORE_LOADED,
                                NULL, NULL, NULL, NULL);
-               if (required && ret < 0) {
-                       ERR("Unable to load module %s", modules[i].name);
+               if (ret < 0) {
+                       if (required) {
+                               ERR("Unable to load required module %s",
+                                               modules[i].name);
+                               goto error;
+                       } else {
+                               DBG("Unable to load optional module %s; continuing",
+                                               modules[i].name);
+                               ret = 0;
+                       }
                } else {
                        DBG("Modprobe successfully %s", modules[i].name);
                }
@@ -245,10 +254,25 @@ static int modprobe_lttng(struct kern_modules_param *modules,
                modprobe[sizeof(modprobe) - 1] = '\0';
                ret = system(modprobe);
                if (ret == -1) {
-                       ERR("Unable to launch modprobe for module %s",
-                                       modules[i].name);
-               } else if (required && WEXITSTATUS(ret) != 0) {
-                       ERR("Unable to load module %s", modules[i].name);
+                       if (required) {
+                               ERR("Unable to launch modprobe for required module %s",
+                                               modules[i].name);
+                               goto error;
+                       } else {
+                               DBG("Unable to launch modprobe for optional module %s; continuing",
+                                               modules[i].name);
+                               ret = 0;
+                       }
+               } else if (WEXITSTATUS(ret) != 0) {
+                       if (required) {
+                               ERR("Unable to load required module %s",
+                                               modules[i].name);
+                               goto error;
+                       } else {
+                               DBG("Unable to load optional module %s; continuing",
+                                               modules[i].name);
+                               ret = 0;
+                       }
                } else {
                        DBG("Modprobe successfully %s", modules[i].name);
                }
@@ -328,10 +352,11 @@ static int append_list_to_probes(const char *list)
 {
        char *next;
        int index = nr_probes, ret;
+       char *tmp_list;
 
        assert(list);
 
-       char *tmp_list = strdup(list);
+       tmp_list = strdup(list);
        if (!tmp_list) {
                PERROR("strdup temp list");
                return -ENOMEM;
@@ -412,8 +437,8 @@ int modprobe_lttng_data(void)
        } else {
                /* Default probes. */
                int def_len = ARRAY_SIZE(kern_modules_probes_default);
-               probes = zmalloc(sizeof(*probes) * def_len);
 
+               probes = zmalloc(sizeof(*probes) * def_len);
                if (!probes) {
                        PERROR("malloc probe list");
                        return -ENOMEM;
This page took 0.024316 seconds and 4 git commands to generate.