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.9.0~16 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=39c9a8244c9558b344510ecf9dfd9e24496a0a94;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 f58f50c65..05027404e 100644 --- a/src/bin/lttng-sessiond/modprobe.c +++ b/src/bin/lttng-sessiond/modprobe.c @@ -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);