}
}
-KMOD_EXPORT int kmod_resolve_alias_options(struct kmod_ctx *ctx,
- const char *given_alias,
- char **options)
-{
- struct kmod_list *modules = NULL, *l;
- char alias[NAME_MAX];
- char *opts = NULL;
- size_t optslen = 0;
- int err;
-
- if (ctx == NULL || options == NULL)
- return -ENOENT;
-
- if (alias_normalize(given_alias, alias, NULL) < 0)
- return -EINVAL;
-
- err = kmod_module_new_from_lookup(ctx, alias, &modules);
- if (err < 0)
- return err;
-
- kmod_list_foreach(l, modules) {
- const char *str = kmod_module_get_options(l->data);
- size_t len;
- void *tmp;
-
- if (str == NULL)
- continue;
- len = strlen(str);
-
- tmp = realloc(opts, optslen + len + 2);
- if (tmp == NULL)
- goto failed;
- opts = tmp;
- if (optslen > 0) {
- opts[optslen] = ' ';
- optslen++;
- }
- memcpy(opts + optslen, str, len);
- optslen += len;
- opts[optslen] = '\0';
- }
-
- kmod_list_foreach(l, ctx->config->options) {
- const struct kmod_list *ml;
- const char *modname = kmod_option_get_modname(l);
- const char *str;
- bool already_done = false;
- size_t len;
- void *tmp;
-
- if (fnmatch(modname, alias, 0) != 0)
- continue;
-
- kmod_list_foreach(ml, modules) {
- const char *mln = kmod_module_get_name(ml->data);
- if (fnmatch(modname, mln, 0) == 0) {
- already_done = true;
- break;
- }
- }
- if (already_done)
- continue;
-
- str = kmod_option_get_options(l);
- len = strlen(str);
- tmp = realloc(opts, optslen + len + 2);
- if (tmp == NULL)
- goto failed;
- opts = tmp;
- if (optslen > 0) {
- opts[optslen] = ' ';
- optslen++;
- }
- memcpy(opts + optslen, str, len);
- optslen += len;
- opts[optslen] = '\0';
- }
-
- DBG(ctx, "alias=%s options='%s'\n", alias, opts);
- kmod_module_unref_list(modules);
- *options = opts;
- return 0;
-
-failed:
- kmod_module_unref_list(modules);
- free(opts);
- ERR(ctx, "out of memory\n");
- *options = NULL;
- return -ENOMEM;
-}
-
const struct kmod_list *kmod_get_options(const struct kmod_ctx *ctx)
{
return ctx->config->options;
const char *alias = NULL;
struct kmod_ctx *ctx;
struct kmod_list *list = NULL, *l;
- char *options;
int load_resources = 0;
int err;
kmod_module_unref(mod);
}
- err = kmod_resolve_alias_options(ctx, alias, &options);
- if (err == 0) {
- printf("Alias options: '%s'\n", options);
- free(options);
- }
-
kmod_module_unref_list(list);
kmod_unref(ctx);