Fix: only unload successfully loaded kernel modules
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 18 Nov 2016 21:35:34 +0000 (16:35 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 18 Nov 2016 21:39:45 +0000 (16:39 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/kern-modules.h
src/bin/lttng-sessiond/modprobe.c

index 26f44578d2f786520f57d8cc6552b5010977d8da..2a35e14f0ae3207e80942d063e03be34b1ceb382 100644 (file)
@@ -29,6 +29,7 @@
 
 struct kern_modules_param {
        char *name;
+       bool loaded;
 };
 
 #endif /* _KERN_MODULES_H */
index ca0467eb37973f169cdebc7966bbb613e83285a9..347829d5dbdd09c29bcd605e9b88e671be827394 100644 (file)
@@ -197,6 +197,7 @@ static int modprobe_lttng(struct kern_modules_param *modules,
                        }
                } else {
                        DBG("Modprobe successfully %s", modules[i].name);
+                       modules[i].loaded = true;
                }
 
                kmod_module_unref(mod);
@@ -271,6 +272,10 @@ static void modprobe_remove_lttng(const struct kern_modules_param *modules,
        for (i = entries - 1; i >= 0; i--) {
                struct kmod_module *mod = NULL;
 
+               if (!modules[i].loaded) {
+                       continue;
+               }
+
                ret = kmod_module_new_from_name(ctx, modules[i].name, &mod);
                if (ret < 0) {
                        PERROR("Failed to create kmod module for %s", modules[i].name);
@@ -337,6 +342,7 @@ static int modprobe_lttng(struct kern_modules_param *modules,
                        }
                } else {
                        DBG("Modprobe successfully %s", modules[i].name);
+                       modules[i].loaded;
                }
        }
 
@@ -351,6 +357,9 @@ static void modprobe_remove_lttng(const struct kern_modules_param *modules,
        char modprobe[256];
 
        for (i = entries - 1; i >= 0; i--) {
+               if (!modules[i].loaded) {
+                       continue;
+               }
                ret = snprintf(modprobe, sizeof(modprobe),
                                "/sbin/modprobe -r -q %s",
                                modules[i].name);
This page took 0.027261 seconds and 4 git commands to generate.