From: Lucas De Marchi Date: Mon, 30 Jan 2012 19:02:06 +0000 (-0200) Subject: libkmod-module: probe: add print_action callback X-Git-Tag: v5~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bd0713deb6be5922b419c6a73361843b8497025;p=thirdparty%2Fkmod.git libkmod-module: probe: add print_action callback This allows to implement dry-run in modprobe without exporting kmod_module_get_probe_list(). --- diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 7d4fbef9..a85eeeaf 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -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); } diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h index bc503fba..a9f6dfcd 100644 --- a/libkmod/libkmod.h +++ b/libkmod/libkmod.h @@ -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);