libkmod-module: Add KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY flag
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 17 Aug 2012 12:38:05 +0000 (09:38 -0300)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 17 Aug 2012 12:42:15 +0000 (09:42 -0300)
With this flag kmod_module_probe_insert_module() check if module is
blacklisted only if it's also an alias. This is needed in order to allow
blacklisting a module by name and effectively blacklisting all its
aliases as module-init-tools was doing.

Before this patch we could load pcspkr module as follows:

/etc/modprobe.d/test.conf:
alias yay pcspkr
blacklist pcspkr

$ modprobe yay

Now libkmod has support to blacklist "yay" because "pcspkr" is blacklisted.

libkmod/libkmod-module.c
libkmod/libkmod.h

index 1271c70..9756d57 100644 (file)
@@ -1172,9 +1172,15 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod,
                        return 0;
        }
 
-       err = flags & (KMOD_PROBE_APPLY_BLACKLIST |
-                                       KMOD_PROBE_APPLY_BLACKLIST_ALL);
-       if (err != 0) {
+       /*
+        * Ugly assignement + check. We need to check if we were told to check
+        * blacklist and also return the reason why we failed.
+        * KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY will take effect only if the
+        * module is an alias, so we also need to check it
+        */
+       if ((mod->alias != NULL && ((err = flags & KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY)))
+                       || (err = flags & KMOD_PROBE_APPLY_BLACKLIST_ALL)
+                       || (err = flags & KMOD_PROBE_APPLY_BLACKLIST)) {
                if (module_is_blacklisted(mod))
                        return err;
        }
index 2f813a8..d03ab19 100644 (file)
@@ -161,6 +161,7 @@ enum kmod_probe {
        /* codes below can be used in return value, too */
        KMOD_PROBE_APPLY_BLACKLIST_ALL =        0x10000,
        KMOD_PROBE_APPLY_BLACKLIST =            0x20000,
+       KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY = 0x40000,
 };
 
 /* Flags to kmod_module_apply_filter() */