chiark / gitweb /
udev-builtin-blkid: modernizations and minor fixes
[elogind.git] / src / udev / udev-builtin-kmod.c
index 57e813f863cc8a0f69a8bebfea06075b36fa3816..5880c3884248f361b63f1d3b530dacc9f47871c7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * load kernel modules
  *
- * Copyright (C) 2011 Kay Sievers <kay.sievers@vrfy.org>
+ * 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
@@ -44,18 +44,18 @@ static int load_module(struct udev *udev, const char *alias)
                 return err;
 
         if (list == NULL)
-                info(udev, "no module matches '%s'\n", alias);
+                log_debug("no module matches '%s'", alias);
 
         kmod_list_foreach(l, list) {
                 struct kmod_module *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)
-                        info(udev, "module '%s' is blacklisted\n", kmod_module_get_name(mod));
+                        log_debug("module '%s' is blacklisted", kmod_module_get_name(mod));
                 else if (err == 0)
-                        info(udev, "inserted '%s'\n", kmod_module_get_name(mod));
+                        log_debug("inserted '%s'", kmod_module_get_name(mod));
                 else
-                        info(udev, "failed to insert '%s'\n", kmod_module_get_name(mod));
+                        log_debug("failed to insert '%s'", kmod_module_get_name(mod));
 
                 kmod_module_unref(mod);
         }
@@ -64,42 +64,35 @@ static int load_module(struct udev *udev, const char *alias)
         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)
 {
         udev_main_log(data, priority, file, line, fn, format, args);
 }
 
-/* needs to re-instantiate the context after a reload */
 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) {
-                ctx = kmod_new(NULL, NULL);
-                if (!ctx)
-                        return -ENOMEM;
-
-                info(udev, "load module index\n");
-                kmod_set_log_fn(ctx, udev_kmod_log, udev);
-                kmod_load_resources(ctx);
-        }
+        if (!ctx)
+                return 0;
 
-        if (argc < 3 || strcmp(argv[1], "load")) {
-                err(udev, "expect: %s load <module>\n", argv[0]);
+        if (argc < 3 || !streq(argv[1], "load")) {
+                log_error("expect: %s load <module>", argv[0]);
                 return EXIT_FAILURE;
         }
 
         for (i = 2; argv[i]; i++) {
-                info(udev, "execute '%s' '%s'\n", argv[1], argv[i]);
+                log_debug("execute '%s' '%s'", argv[1], argv[i]);
                 load_module(udev, argv[i]);
         }
 
         return EXIT_SUCCESS;
 }
 
-/* called at udev startup */
+/* called at udev startup and reload */
 static int builtin_kmod_init(struct udev *udev)
 {
         if (ctx)
@@ -109,7 +102,7 @@ static int builtin_kmod_init(struct udev *udev)
         if (!ctx)
                 return -ENOMEM;
 
-        info(udev, "load module index\n");
+        log_debug("load module index");
         kmod_set_log_fn(ctx, udev_kmod_log, udev);
         kmod_load_resources(ctx);
         return 0;
@@ -118,17 +111,17 @@ static int builtin_kmod_init(struct udev *udev)
 /* called on udev shutdown and reload request */
 static void builtin_kmod_exit(struct udev *udev)
 {
-        info(udev, "unload module index\n");
+        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)
 {
-        info(udev, "validate module index\n");
-        if (kmod_validate_resources(ctx) != KMOD_RESOURCES_OK)
-                return true;
-        return false;
+        log_debug("validate module index");
+        if (!ctx)
+                return false;
+        return (kmod_validate_resources(ctx) != KMOD_RESOURCES_OK);
 }
 
 const struct udev_builtin udev_builtin_kmod = {