From: Lucas De Marchi Date: Fri, 13 Jan 2012 04:35:34 +0000 (-0200) Subject: modprobe: dump configuration X-Git-Tag: v4~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bc43496a87820bac96948497a21e0dfd84477227;p=platform%2Fupstream%2Fkmod.git modprobe: dump configuration --- diff --git a/TODO b/TODO index e947796..2e6987b 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,9 @@ Features: * Add functions to list all modules known by modules.dep * provide 1:1 compatibility with module-init-tools's modprobe - - dump configuration + - dump modules.alias and modules.symbols + +* Add docs to kmod_config_* functions * Add manpages: copy them from module-init-tools and make the necessary changes @@ -103,6 +105,12 @@ modprobe install "echo bli" install "echo bla" +* kmod doesn't dump the configuration as is in the config files. Instead it + dumps the configuration as it was parsed. Therefore, comments and file names + are not dumped, but on the good side we know what the exact configuration + kmod is using. We did this because if we only want to know the entire content + of configuration files, it's enough to use find(1) in modprobe.d directories + depmod ------ diff --git a/tools/kmod-modprobe.c b/tools/kmod-modprobe.c index 29b7088..c90141b 100644 --- a/tools/kmod-modprobe.c +++ b/tools/kmod-modprobe.c @@ -32,6 +32,7 @@ #include "libkmod.h" #include "libkmod-array.h" +#include "macro.h" static int log_priority = LOG_CRIT; static int use_syslog = 0; @@ -211,16 +212,42 @@ static inline void _log(int prio, const char *fmt, ...) static int show_config(struct kmod_ctx *ctx) { - ERR("TODO - config is missing in kmod.\n"); - /* - * needs: - * struct kmod_list *kmod_get_config(struct kmod_ctx *ctx); - * kmod_config_get_type() {alias,options,blacklist,install,remove,softdeps} - * kmod_config_get_key() - * kmod_config_get_value() - * kmod_config_unref_list() - */ - return -ENOENT; + struct config_iterators { + const char *name; + struct kmod_config_iter *(*get_iter)(const struct kmod_ctx *ctx); + } ci[] = { + { "blacklist", kmod_config_get_blacklists }, + { "install", kmod_config_get_install_commands }, + { "remove", kmod_config_get_remove_commands }, + { "alias", kmod_config_get_aliases }, + { "option", kmod_config_get_options }, + { "softdep", kmod_config_get_softdeps }, + }; + size_t i; + + for (i = 0; i < ARRAY_SIZE(ci); i++) { + struct kmod_config_iter *iter = ci[i].get_iter(ctx); + + if (iter == NULL) + continue; + + while (kmod_config_iter_next(iter)) { + const char *val; + + printf("%s %s", ci[i].name, + kmod_config_iter_get_key(iter)); + val = kmod_config_iter_get_value(iter); + if (val != NULL) { + putchar(' '); + puts(val); + } else + putchar('\n'); + } + + kmod_config_iter_free_iter(iter); + } + + return 0; } static int show_modversions(struct kmod_ctx *ctx, const char *filename)