kmod_module_insert_module will never return -EEXIST given the check for
initstate prior to the call. Check for EPERM instead and throw an
appropriate error when an unprivileged user attempts to load a module.
---
 TODO                  |    2 --
 tools/kmod-modprobe.c |   10 ++++------
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/TODO b/TODO
index 5dd906d..6bd5736 100644
--- a/TODO
+++ b/TODO
@@ -21,8 +21,6 @@ Features:
    - deal with dependency loop
    - break dependency loop when all it needs is to check if the module is
      already loaded
-   - check if user has permission to load module and print an error instead of
-     returning 0
 
 * Add manpages: copy them from module-init-tools and make the necessary changes
 
diff --git a/tools/kmod-modprobe.c b/tools/kmod-modprobe.c
index 7d9c667..5289c44 100644
--- a/tools/kmod-modprobe.c
+++ b/tools/kmod-modprobe.c
@@ -807,12 +807,10 @@ static int insmod_do(struct kmod_module *mod, const char 
*extra_opts)
                        flags |= KMOD_INSERT_FORCE_VERMAGIC;
 
                err = kmod_module_insert_module(mod, flags, opts);
-               if (err == -EEXIST) {
-                       if (!first_time)
-                               err = 0;
-                       else
-                               ERR("Module %s already in kernel.\n",
-                                       kmod_module_get_name(mod));
+               if (err == -EPERM) {
+                       ERR("could not insert '%s': %s\n", 
kmod_module_get_name(mod),
+                                       strerror(-err));
+                       goto error;
                }
        }
 
-- 
1.7.8.3

--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to