]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod-module: probe: add print_action callback
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Mon, 30 Jan 2012 19:02:06 +0000 (17:02 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 31 Jan 2012 16:08:57 +0000 (14:08 -0200)
This allows to implement dry-run in modprobe without exporting
kmod_module_get_probe_list().

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

index 7d4fbef9f38f2bfb39489f1bf25e78f5240b10c4..a85eeeafb9841ae92e23d6bec0219d491b9280af 100644 (file)
@@ -1090,6 +1090,9 @@ static int kmod_module_get_probe_list(struct kmod_module *mod,
  * to @mod, not to its dependencies.
  * @run_install: function to run when @mod is backed by an install command.
  * @data: data to give back to @run_install callback
+ * @print_action: function to call with the action being taken (install or
+ * insmod). It's useful for tools like modprobe when running with verbose
+ * output or in dry-run mode.
  *
  * Insert a module in Linux kernel resolving dependencies, soft dependencies,
  * install commands and applying blacklist.
@@ -1107,7 +1110,10 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod,
                        unsigned int flags, const char *extra_options,
                        int (*run_install)(struct kmod_module *m,
                                                const char *cmd, void *data),
-                       const void *data)
+                       const void *data,
+                       void (*print_action)(struct kmod_module *m,
+                                               bool install,
+                                               const char *options))
 {
        struct kmod_list *list = NULL, *l;
        struct probe_insert_cb cb;
@@ -1161,6 +1167,9 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod,
                                free(options);
                                break;
                        }
+                       if (print_action != NULL)
+                               print_action(m, true, options ?: "");
+
                        err = module_do_install_commands(m, options, &cb);
                } else {
                        int state = kmod_module_get_initstate(m);
@@ -1178,6 +1187,9 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod,
                                free(options);
                                continue;
                        }
+                       if (print_action != NULL)
+                               print_action(m, false, options ?: "");
+
                        err = kmod_module_insert_module(m, flags, options);
                }
 
index bc503fba7a10dacc73fc41477a900a93ef6e8658..a9f6dfcd4644b0384844733ed6ab778df14bf7cc 100644 (file)
@@ -163,7 +163,8 @@ int kmod_module_insert_module(struct kmod_module *mod, unsigned int flags, const
 int kmod_module_probe_insert_module(struct kmod_module *mod,
                        unsigned int flags, const char *extra_options,
                        int (*run_install)(struct kmod_module *m, const char *cmdline, void *data),
-                       const void *data);
+                       const void *data,
+                       void (*print_action)(struct kmod_module *m, bool install, const char *options));
 
 const char *kmod_module_get_name(const struct kmod_module *mod);
 const char *kmod_module_get_path(const struct kmod_module *mod);