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:35:34 +0000 (16:35 -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 f58f50c65c3f4f8284a6bd9bf7a2af1bb548a00a..05027404e42587cc9abbe34c57c4f8722a68a127 100644 (file)
@@ -198,6 +198,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);
@@ -272,6 +273,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);
@@ -338,6 +343,7 @@ static int modprobe_lttng(struct kern_modules_param *modules,
                        }
                } else {
                        DBG("Modprobe successfully %s", modules[i].name);
+                       modules[i].loaded;
                }
        }
 
@@ -352,6 +358,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.026784 seconds and 4 git commands to generate.