chiark / gitweb /
builtin: firmware - move 'firmware' tool to builtins
[elogind.git] / udev / udev-builtin-kmod.c
index 41de2ebc37eb2701d7a4b20c140d66ebaa96c043..e6c4d95109f365076c35175f57d8252c2c0a2024 100644 (file)
@@ -2,7 +2,7 @@
  * load kernel modules
  *
  * Copyright (C) 2011 Kay Sievers <kay.sievers@vrfy.org>
- * Copyright (C) 2011  ProFUSION embedded systems
+ * 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
@@ -321,36 +321,45 @@ static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool te
        struct udev *udev = udev_device_get_udev(dev);
        int i;
 
-       if (!ctx)
-               return EXIT_FAILURE;
+       if (!ctx) {
+               ctx = kmod_new(NULL, NULL);
+               if (!ctx)
+                       return -ENOMEM;
 
-       if (argc < 3) {
-               err(udev, "missing command + argument\n");
+               info(udev, "load module index\n");
+               kmod_load_resources(ctx);
+       }
+
+       if (argc < 3 || strcmp(argv[1], "load")) {
+               err(udev, "expect: %s load <module>\n", argv[0]);
                return EXIT_FAILURE;
        }
 
        for (i = 2; argv[i]; i++) {
-               info(udev, "%s '%s'\n", argv[1], argv[i]);
+               info(udev, "execute '%s' '%s'\n", argv[1], argv[i]);
                insmod(ctx, argv[i], NULL);
        }
 
        return EXIT_SUCCESS;
 }
 
-static int builtin_kmod_load(struct udev *udev)
+static int builtin_kmod_init(struct udev *udev)
 {
-       kmod_unref(ctx);
+       if (ctx)
+               return 0;
+
        ctx = kmod_new(NULL, NULL);
        if (!ctx)
                return -ENOMEM;
 
        info(udev, "load module index\n");
+       kmod_load_resources(ctx);
        return 0;
 }
 
-static int builtin_kmod_unload(struct udev *udev)
+static int builtin_kmod_exit(struct udev *udev)
 {
-       kmod_unref(ctx);
+       ctx = kmod_unref(ctx);
        info(udev, "unload module index\n");
        return 0;
 }
@@ -358,8 +367,8 @@ static int builtin_kmod_unload(struct udev *udev)
 const struct udev_builtin udev_builtin_kmod = {
        .name = "kmod",
        .cmd = builtin_kmod,
-       .load = builtin_kmod_load,
-       .unload = builtin_kmod_unload,
+       .init = builtin_kmod_init,
+       .exit = builtin_kmod_exit,
        .help = "kernel module loader",
        .run_once = false,
 };