* provide ELF manipulation to implement modinfo
-* Add lookup for install commands in kmod_module_new_from_lookup()
-
-* Add lookup for remove commands
-
* Add functions to dump configuration
* Add functions list all modules known by modules.dep
err = kmod_lookup_alias_from_symbols_file(ctx, alias, list);
CHECK_ERR_AND_FINISH(err, fail, list, finish);
-// TODO: add lookup for install commands here.
+ err = kmod_lookup_alias_from_commands(ctx, alias, list);
+ CHECK_ERR_AND_FINISH(err, fail, list, finish);
err = kmod_lookup_alias_from_aliases_file(ctx, alias, list);
CHECK_ERR_AND_FINISH(err, fail, list, finish);
return mod->install_commands;
}
+void kmod_module_set_install_commands(struct kmod_module *mod, const char *cmd)
+{
+ mod->init.install_commands = true;
+ mod->install_commands = cmd;
+}
+
/**
* kmod_module_get_remove_commands:
* @mod: kmod module
return mod->remove_commands;
}
+void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd)
+{
+ mod->init.remove_commands = true;
+ mod->remove_commands = cmd;
+}
+
/**
* SECTION:libkmod-loaded
* @short_description: currently loaded modules
int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
+int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) __attribute__((nonnull(1,2)));
int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, const char *name, struct kmod_module **mod);
char *modname_normalize(const char *modname, char buf[NAME_MAX], size_t *len) __attribute__((nonnull(1, 2)));
int kmod_module_parse_depline(struct kmod_module *mod, char *line) __attribute__((nonnull(1, 2)));
+void kmod_module_set_install_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1)));
+void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1)));
/* libkmod-hash.c */
struct kmod_hash;
return err;
}
+int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name,
+ struct kmod_list **list)
+{
+ struct kmod_config *config = ctx->config;
+ struct kmod_list *l, *node;
+ int err, nmatch = 0;
+
+ kmod_list_foreach(l, config->install_commands) {
+ const char *modname = kmod_command_get_modname(l);
+
+ if (streq(modname, name)) {
+ const char *cmd = kmod_command_get_command(l);
+ struct kmod_module *mod;
+
+ err = kmod_module_new_from_name(ctx, modname, &mod);
+ if (err < 0) {
+ ERR(ctx, "%s\n", strerror(-err));
+ return err;
+ }
+
+ node = kmod_list_append(*list, mod);
+ if (node == NULL) {
+ ERR(ctx, "out of memory\n");
+ return -ENOMEM;
+ }
+
+ *list = node;
+ nmatch = 1;
+
+ kmod_module_set_install_commands(mod, cmd);
+
+ /*
+ * match only the first one, like modprobe from
+ * module-init-tools does
+ */
+ break;
+ }
+ }
+
+ if (nmatch)
+ return nmatch;
+
+ kmod_list_foreach(l, config->remove_commands) {
+ const char *modname = kmod_command_get_modname(l);
+
+ if (streq(modname, name)) {
+ const char *cmd = kmod_command_get_command(l);
+ struct kmod_module *mod;
+
+ err = kmod_module_new_from_name(ctx, modname, &mod);
+ if (err < 0) {
+ ERR(ctx, "%s\n", strerror(-err));
+ return err;
+ }
+
+ node = kmod_list_append(*list, mod);
+ if (node == NULL) {
+ ERR(ctx, "out of memory\n");
+ return -ENOMEM;
+ }
+
+ *list = node;
+ nmatch = 1;
+
+ kmod_module_set_remove_commands(mod, cmd);
+
+ /*
+ * match only the first one, like modprobe from
+ * module-init-tools does
+ */
+ break;
+ }
+ }
+
+ return nmatch;
+}
+
/**
* kmod_module_get_filtered_blacklist:
* @ctx: kmod library context