]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-kmod: use the generic module_load() function
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 6 Jul 2018 10:28:09 +0000 (12:28 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 19 Jul 2018 16:28:21 +0000 (18:28 +0200)
There should be no functional change.

src/modules-load/modules-load.c
src/shared/module-util.c
src/shared/module-util.h
src/udev/udev-builtin-kmod.c

index b3a4e818b608feb4a9cde9317807f16520e13e6c..4b0b9f4c806b055d95a936cc31930e66c449423d 100644 (file)
@@ -92,7 +92,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
                 if (strchr(COMMENTS "\n", *l))
                         continue;
 
-                k = module_load_and_warn(ctx, l);
+                k = module_load_and_warn(ctx, l, true);
                 if (k < 0 && r == 0)
                         r = k;
         }
@@ -189,7 +189,7 @@ int main(int argc, char *argv[]) {
                 char **fn, **i;
 
                 STRV_FOREACH(i, arg_proc_cmdline_modules) {
-                        k = module_load_and_warn(ctx, *i);
+                        k = module_load_and_warn(ctx, *i, true);
                         if (k < 0 && r == 0)
                                 r = k;
                 }
index 36f4f364c18f622380ee960db7c01b65bae65608..af6a9b01e7504b07546d09479eacc0e5fd7fa189 100644 (file)
@@ -4,20 +4,25 @@
 
 #include "module-util.h"
 
-int module_load_and_warn(struct kmod_ctx *ctx, const char *module) {
+int module_load_and_warn(struct kmod_ctx *ctx, const char *module, bool verbose) {
         const int probe_flags = KMOD_PROBE_APPLY_BLACKLIST;
         struct kmod_list *itr;
         _cleanup_(kmod_module_unref_listp) struct kmod_list *modlist = NULL;
         int r = 0;
 
+        /* verbose==true means we should log at non-debug level if we
+         * fail to find or load the module. */
+
         log_debug("Loading module: %s", module);
 
         r = kmod_module_new_from_lookup(ctx, module, &modlist);
         if (r < 0)
-                return log_error_errno(r, "Failed to lookup module alias '%s': %m", module);
+                return log_full_errno(verbose ? LOG_ERR : LOG_DEBUG, r,
+                                      "Failed to lookup module alias '%s': %m", module);
 
         if (!modlist) {
-                log_error("Failed to find module '%s'", module);
+                log_full_errno(verbose ? LOG_ERR : LOG_DEBUG, r,
+                               "Failed to find module '%s'", module);
                 return -ENOENT;
         }
 
@@ -30,7 +35,8 @@ int module_load_and_warn(struct kmod_ctx *ctx, const char *module) {
 
                 switch (state) {
                 case KMOD_MODULE_BUILTIN:
-                        log_info("Module '%s' is builtin", kmod_module_get_name(mod));
+                        log_full(verbose ? LOG_INFO : LOG_DEBUG,
+                                 "Module '%s' is builtin", kmod_module_get_name(mod));
                         break;
 
                 case KMOD_MODULE_LIVE:
@@ -40,15 +46,17 @@ int module_load_and_warn(struct kmod_ctx *ctx, const char *module) {
                 default:
                         err = kmod_module_probe_insert_module(mod, probe_flags,
                                                               NULL, NULL, NULL, NULL);
-
                         if (err == 0)
-                                log_info("Inserted module '%s'", kmod_module_get_name(mod));
+                                log_full(verbose ? LOG_INFO : LOG_DEBUG,
+                                         "Inserted module '%s'", kmod_module_get_name(mod));
                         else if (err == KMOD_PROBE_APPLY_BLACKLIST)
-                                log_info("Module '%s' is blacklisted", kmod_module_get_name(mod));
+                                log_full(verbose ? LOG_INFO : LOG_DEBUG,
+                                         "Module '%s' is blacklisted", kmod_module_get_name(mod));
                         else {
                                 assert(err < 0);
 
-                                log_full_errno(err == ENODEV ? LOG_NOTICE :
+                                log_full_errno(!verbose ? LOG_DEBUG :
+                                               err == ENODEV ? LOG_NOTICE :
                                                err == ENOENT ? LOG_WARNING :
                                                                LOG_ERR,
                                                err,
index 16cac90258f54bfa802d17618b0e129cc4b696bf..c386c5b459219550391b34a54ce80390e035c36a 100644 (file)
@@ -9,4 +9,4 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_ctx*, kmod_unref);
 DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_module*, kmod_module_unref);
 DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_list*, kmod_module_unref_list);
 
-int module_load_and_warn(struct kmod_ctx *ctx, const char *module);
+int module_load_and_warn(struct kmod_ctx *ctx, const char *module, bool verbose);
index e24e8e55e2242bb2601e40cda73dbe720d54160b..f5e09cebde675c2817c9da365d880ce5a73773a3 100644 (file)
 
 static struct kmod_ctx *ctx = NULL;
 
-static int load_module(struct udev *udev, const char *alias) {
-        _cleanup_(kmod_module_unref_listp) struct kmod_list *list = NULL;
-        struct kmod_list *l;
-        int err;
-
-        err = kmod_module_new_from_lookup(ctx, alias, &list);
-        if (err < 0)
-                return err;
-
-        if (list == NULL)
-                log_debug("No module matches '%s'", alias);
-
-        kmod_list_foreach(l, list) {
-                _cleanup_(kmod_module_unrefp) struct kmod_module *mod = NULL;
-
-                mod = kmod_module_get_module(l);
-
-                err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL);
-                if (err == KMOD_PROBE_APPLY_BLACKLIST)
-                        log_debug("Module '%s' is blacklisted", kmod_module_get_name(mod));
-                else if (err == 0)
-                        log_debug("Inserted '%s'", kmod_module_get_name(mod));
-                else
-                        log_debug("Failed to insert '%s'", kmod_module_get_name(mod));
-        }
-
-        return err;
-}
-
 _printf_(6,0) static void udev_kmod_log(void *data, int priority, const char *file, int line, const char *fn, const char *format, va_list args) {
         log_internalv(priority, 0, file, line, fn, format, args);
 }
 
 static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool test) {
-        struct udev *udev = udev_device_get_udev(dev);
         int i;
 
         if (!ctx)
@@ -65,7 +35,7 @@ static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool te
 
         for (i = 2; argv[i]; i++) {
                 log_debug("Execute '%s' '%s'", argv[1], argv[i]);
-                load_module(udev, argv[i]);
+                (void) module_load_and_warn(ctx, argv[i], false);
         }
 
         return EXIT_SUCCESS;