]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/udev/udev-builtin-kmod.c
Merge pull request #15669 from andir/systemd-ipv6-pd-subnet-id
[thirdparty/systemd.git] / src / udev / udev-builtin-kmod.c
index 2530fdfd2347cf7df95ea2b0a685c819ec4cd80a..b3daddcdd5465c29ba2f04c2520b4b456c93f33e 100644 (file)
@@ -2,90 +2,42 @@
 /*
  * load kernel modules
  *
- * Copyright (C) 2011-2012 Kay Sievers <kay@vrfy.org>
- * Copyright (C) 2011 ProFUSION embedded systems
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * Copyright © 2011 ProFUSION embedded systems
  */
 
 #include <errno.h>
-#include <libkmod.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 #include "module-util.h"
 #include "string-util.h"
-#include "udev.h"
+#include "udev-builtin.h"
 
 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);
+static int builtin_kmod(sd_device *dev, int argc, char *argv[], bool test) {
         int i;
 
         if (!ctx)
                 return 0;
 
-        if (argc < 3 || !streq(argv[1], "load")) {
-                log_error("expect: %s load <module>", argv[0]);
-                return EXIT_FAILURE;
-        }
+        if (argc < 3 || !streq(argv[1], "load"))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "%s: expected: load <module>", argv[0]);
 
-        for (i = 2; argv[i]; i++) {
-                log_debug("Execute '%s' '%s'", argv[1], argv[i]);
-                load_module(udev, argv[i]);
-        }
+        for (i = 2; argv[i]; i++)
+                (void) module_load_and_warn(ctx, argv[i], false);
 
-        return EXIT_SUCCESS;
+        return 0;
 }
 
 /* called at udev startup and reload */
-static int builtin_kmod_init(struct udev *udev) {
+static int builtin_kmod_init(void) {
         if (ctx)
                 return 0;
 
@@ -94,26 +46,26 @@ static int builtin_kmod_init(struct udev *udev) {
                 return -ENOMEM;
 
         log_debug("Load module index");
-        kmod_set_log_fn(ctx, udev_kmod_log, udev);
+        kmod_set_log_fn(ctx, udev_kmod_log, NULL);
         kmod_load_resources(ctx);
         return 0;
 }
 
 /* called on udev shutdown and reload request */
-static void builtin_kmod_exit(struct udev *udev) {
+static void builtin_kmod_exit(void) {
         log_debug("Unload module index");
         ctx = kmod_unref(ctx);
 }
 
 /* called every couple of seconds during event activity; 'true' if config has changed */
-static bool builtin_kmod_validate(struct udev *udev) {
+static bool builtin_kmod_validate(void) {
         log_debug("Validate module index");
         if (!ctx)
                 return false;
         return (kmod_validate_resources(ctx) != KMOD_RESOURCES_OK);
 }
 
-const struct udev_builtin udev_builtin_kmod = {
+const UdevBuiltin udev_builtin_kmod = {
         .name = "kmod",
         .cmd = builtin_kmod,
         .init = builtin_kmod_init,