summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEzequiel Garcia <ezequiel@collabora.com>2019-03-08 17:39:07 -0300
committerLucas De Marchi <lucas.demarchi@intel.com>2019-03-08 13:06:52 -0800
commitea3e508f61251b16567f888042f6c4c60b48a4e0 (patch)
tree957f807b949e4c15bb269d97fa6f4f218a9b692a
parentf8b8d7b330433511d19a936ddfc7b7d1af5490b5 (diff)
downloadkmod-ea3e508f61251b16567f888042f6c4c60b48a4e0.tar.gz
kmod-ea3e508f61251b16567f888042f6c4c60b48a4e0.tar.bz2
kmod-ea3e508f61251b16567f888042f6c4c60b48a4e0.zip
tools: Print a message if refcnt attribute is missing
Currently, check_module_inuse returns a wrong user message if the kernel is built without module unloading support. Fix it by returning a more specific error, in case 'refcnt' attribute is missing.
-rw-r--r--tools/remove.c9
-rw-r--r--tools/rmmod.c9
2 files changed, 12 insertions, 6 deletions
diff --git a/tools/remove.c b/tools/remove.c
index 07e2cc0..387ef0e 100644
--- a/tools/remove.c
+++ b/tools/remove.c
@@ -44,7 +44,7 @@ static void help(void)
static int check_module_inuse(struct kmod_module *mod) {
struct kmod_list *holders;
- int state;
+ int state, ret;
state = kmod_module_get_initstate(mod);
@@ -74,12 +74,15 @@ static int check_module_inuse(struct kmod_module *mod) {
return -EBUSY;
}
- if (kmod_module_get_refcnt(mod) != 0) {
+ ret = kmod_module_get_refcnt(mod);
+ if (ret > 0) {
ERR("Module %s is in use\n", kmod_module_get_name(mod));
return -EBUSY;
+ } else if (ret == -ENOENT) {
+ ERR("Module unloading is not supported\n");
}
- return 0;
+ return ret;
}
static int do_remove(int argc, char *argv[])
diff --git a/tools/rmmod.c b/tools/rmmod.c
index bcdea4c..3942e7b 100644
--- a/tools/rmmod.c
+++ b/tools/rmmod.c
@@ -63,7 +63,7 @@ static void help(void)
static int check_module_inuse(struct kmod_module *mod) {
struct kmod_list *holders;
- int state;
+ int state, ret;
state = kmod_module_get_initstate(mod);
@@ -93,12 +93,15 @@ static int check_module_inuse(struct kmod_module *mod) {
return -EBUSY;
}
- if (kmod_module_get_refcnt(mod) != 0) {
+ ret = kmod_module_get_refcnt(mod);
+ if (ret > 0) {
ERR("Module %s is in use\n", kmod_module_get_name(mod));
return -EBUSY;
+ } else if (ret == -ENOENT) {
+ ERR("Module unloading is not supported\n");
}
- return 0;
+ return ret;
}
static int do_rmmod(int argc, char *argv[])