From: Jérémie Galarneau Date: Fri, 18 Nov 2016 21:35:34 +0000 (-0500) Subject: Fix: only unload successfully loaded kernel modules X-Git-Tag: v2.8.3~3 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=e6a9d253500d10bfbb64b2ce51e39e73c6cc2296;p=lttng-tools.git Fix: only unload successfully loaded kernel modules Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/kern-modules.h b/src/bin/lttng-sessiond/kern-modules.h index 26f44578d..2a35e14f0 100644 --- a/src/bin/lttng-sessiond/kern-modules.h +++ b/src/bin/lttng-sessiond/kern-modules.h @@ -29,6 +29,7 @@ struct kern_modules_param { char *name; + bool loaded; }; #endif /* _KERN_MODULES_H */ diff --git a/src/bin/lttng-sessiond/modprobe.c b/src/bin/lttng-sessiond/modprobe.c index ca0467eb3..347829d5d 100644 --- a/src/bin/lttng-sessiond/modprobe.c +++ b/src/bin/lttng-sessiond/modprobe.c @@ -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);