From 0e9bd2d1caec93432fe897bd6e272f74f78b4e73 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 31 Dec 2011 18:02:45 -0500 Subject: [PATCH] kmodprobe: post-remove module deps with 0 refcnt --- TODO | 2 -- tools/kmod-modprobe.c | 13 ++++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index c7d162c9..69a0a0d3 100644 --- a/TODO +++ b/TODO @@ -18,8 +18,6 @@ Features: * provide 1:1 compatibility with module-init-tools's modprobe - dump configuration - - 'modprobe -r' should remove modules which usecount became 0 because of - module's removal * Add kmod_validate(). It checks if all config files and indexes are still valid. We need to save the mtime of each config dir when starting up and when diff --git a/tools/kmod-modprobe.c b/tools/kmod-modprobe.c index b8d79b0e..2a649dda 100644 --- a/tools/kmod-modprobe.c +++ b/tools/kmod-modprobe.c @@ -418,7 +418,7 @@ static int rmmod_do_dependencies(struct kmod_module *parent) static int rmmod_do(struct kmod_module *mod) { const char *modname = kmod_module_get_name(mod); - struct kmod_list *pre = NULL, *post = NULL; + struct kmod_list *pre = NULL, *post = NULL, *deps, *itr; int err; if (!ignore_commands) { @@ -508,6 +508,17 @@ done: } } + deps = kmod_module_get_dependencies(mod); + if (deps) { + kmod_list_foreach(itr, deps) { + struct kmod_module *dep = kmod_module_get_module(itr); + if (kmod_module_get_refcnt(dep) == 0) { + rmmod_do(dep); + } + } + kmod_module_unref_list(deps); + } + error: kmod_module_unref_list(pre); kmod_module_unref_list(post); -- 2.47.2