]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
modprobe: check for EPERM on insertion
authorDave Reisner <dreisner@archlinux.org>
Tue, 10 Jan 2012 18:36:27 +0000 (13:36 -0500)
committerDave Reisner <dreisner@archlinux.org>
Wed, 11 Jan 2012 03:33:05 +0000 (22:33 -0500)
Throw an appropriate error when an unprivileged user attempts to load a
module.

TODO
tools/kmod-modprobe.c

diff --git a/TODO b/TODO
index 2d45006cb24834fe308d0faf779a2ce05aed3696..bd29f25b9fe0850af1acf2380d1f856ebd781fbc 100644 (file)
--- 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
 
index 7d9c667f465595afab051de0ef16fd4a2dd66366..698f5fff3087158878b369324e71c799df2c7ab9 100644 (file)
@@ -807,12 +807,21 @@ 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) {
+               switch (err) {
+               case -EEXIST:
+                       /* we checked for EEXIST with an earlier call to retrieve the initstate,
+                        * but to avoid a race condition, we don't make any assumptions and
+                        * handle the error again here */
                        if (!first_time)
                                err = 0;
                        else
                                ERR("Module %s already in kernel.\n",
                                        kmod_module_get_name(mod));
+                       goto error;
+               case -EPERM:
+                       ERR("could not insert '%s': %s\n", kmod_module_get_name(mod),
+                                       strerror(-err));
+                       goto error;
                }
        }