modprobe: dump configuration
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 13 Jan 2012 04:35:34 +0000 (02:35 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 13 Jan 2012 13:12:41 +0000 (11:12 -0200)
TODO
tools/kmod-modprobe.c

diff --git a/TODO b/TODO
index e947796..2e6987b 100644 (file)
--- 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
 ------
 
index 29b7088..c90141b 100644 (file)
@@ -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)