X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=kmodloader.c;h=865f2e2eab5ebc32ee993b68a3e473e3e76fc8b8;hb=HEAD;hp=12878391d2e54336e1ca595c5b49902106960a95;hpb=6a59975afc2c390e64cb7a23798f3b0c10964884;p=project%2Fubox.git diff --git a/kmodloader.c b/kmodloader.c index 1287839..8fd989f 100644 --- a/kmodloader.c +++ b/kmodloader.c @@ -282,12 +282,16 @@ alloc_module_node(const char *name, struct module *m, bool is_alias) 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) { @@ -317,7 +321,8 @@ alloc_module(const char *name, const char * const *aliases, int naliases, const 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; } @@ -892,7 +897,7 @@ static int print_usage(char *arg) 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) @@ -913,19 +918,19 @@ static int main_insmod(int argc, char **argv) } - 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++; } @@ -937,19 +942,18 @@ static int main_insmod(int argc, char **argv) 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(); @@ -1029,7 +1033,7 @@ static int main_lsmod(int argc, char **argv) static int main_modinfo(int argc, char **argv) { - struct module *m; + struct module_node *mn; int rv = -1; char *name; @@ -1043,14 +1047,19 @@ static int main_modinfo(int argc, char **argv) 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(); @@ -1365,7 +1374,7 @@ int main(int argc, char **argv) { 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);