mn->avl.key = strcpy(_name, name);
mn->m = m;
mn->is_alias = is_alias;
- avl_insert(&modules, &mn->avl);
- m->refcnt += 1;
+ if (avl_insert(&modules, &mn->avl) == 0)
+ m->refcnt += 1;
+ else
+ free(mn);
}
return mn;
}
+static int avl_modcmp(const void *k1, const void *k2, void *ptr);
+
static struct module *
alloc_module(const char *name, const char * const *aliases, int naliases, const char *depends, int size)
{
m->refcnt = 0;
alloc_module_node(m->name, m, false);
for (i = 0; i < naliases; i++)
- alloc_module_node(aliases[i], m, true);
+ if (avl_modcmp(m->name, aliases[i], NULL))
+ alloc_module_node(aliases[i], m, true);
return m;
}
static int main_insmod(int argc, char **argv)
{
- char *name, *cur, *options = NULL;
+ char *name, *path, *cur, *opts = NULL;
int i, ret = -1, len;
if (argc < 2)
}
- for (len = 0, i = 2; i < argc; i++)
+ for (len = 1, i = 2; i < argc; i++)
len += strlen(argv[i]) + 1;
- options = malloc(len);
- if (!options) {
+ opts = malloc(len);
+ if (!opts) {
ULOG_ERR("out of memory\n");
goto err;
}
- options[0] = 0;
- cur = options;
+ opts[0] = 0;
+ cur = opts;
for (i = 2; i < argc; i++) {
- if (options[0]) {
+ if (opts[0]) {
*cur = ' ';
cur++;
}
goto err;
}
- if (get_module_path(argv[1])) {
- name = argv[1];
- } else if (!get_module_path(name)) {
+ if (!((path = get_module_path(argv[1])) ||
+ (path = get_module_path(name)))) {
fprintf(stderr, "Failed to find %s. Maybe it is a built in module ?\n", name);
goto err;
}
- ret = insert_module(get_module_path(name), options);
+ ret = insert_module(path, opts);
if (ret)
ULOG_ERR("failed to insert %s\n", get_module_path(name));
err:
- free(options);
+ free(opts);
free_modules();
free_module_folders();
static int main_modinfo(int argc, char **argv)
{
- struct module *m;
+ struct module_node *mn;
int rv = -1;
char *name;
return -1;
name = get_module_name(argv[1]);
- m = find_module(name);
- if (!m) {
+ mn = avl_find_element(&modules, name, mn, avl);
+ if (!mn) {
ULOG_ERR("cannot find module - %s\n", argv[1]);
goto err;
}
- print_modinfo(m);
-
+ if (!mn->avl.leader)
+ print_modinfo(mn->m);
+ else
+ do {
+ print_modinfo(mn->m);
+ mn = (struct module_node *) mn->avl.list.next;
+ } while (!avl_modcmp(name, mn->avl.key, NULL));
rv = 0;
err:
free_modules();
{
char *exec = basename(*argv);
- avl_init(&modules, avl_modcmp, false, NULL);
+ avl_init(&modules, avl_modcmp, true, NULL);
if (!strcmp(exec, "insmod"))
return main_insmod(argc, argv);