From: Bernhard Reutner-Fischer Date: Wed, 28 May 2008 14:20:20 +0000 (-0000) Subject: - misc. improvements and shrinkage X-Git-Tag: 1_11_0~156 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=634b0221088680153f4abe18db0504fda75a6d86;p=oweals%2Fbusybox.git - misc. improvements and shrinkage --- diff --git a/modutils/depmod.c b/modutils/depmod.c index 15b49f031..e061501f6 100644 --- a/modutils/depmod.c +++ b/modutils/depmod.c @@ -18,8 +18,8 @@ * for each depends, look through our list of full paths and emit if found */ struct globals { - llist_t *lst; - unsigned moddir_base_len; + llist_t *lst; /* modules without their corresponding extension */ + size_t moddir_base_len; /* length of the "-b basedir" */ }; #define G (*(struct globals*)&bb_common_bufsiz1) /* We have to zero it out because of NOEXEC */ @@ -28,7 +28,10 @@ struct globals { static int fill_lst(const char *modulename, struct stat ATTRIBUTE_UNUSED *sb, void ATTRIBUTE_UNUSED *data, int ATTRIBUTE_UNUSED depth) { - if (last_char_is(modulename, 'o') != NULL) /* it is a module, remember it */ + /* We get a file here. If the file does not have ".ko" but an + * intermittent dentry has, it's just their fault. + */ + if (strrstr(modulename, ".ko") != NULL) llist_add_to(&G.lst, xstrdup(modulename + G.moddir_base_len)); return TRUE; } @@ -37,17 +40,18 @@ static int fileAction(const char *fname, struct stat *sb, void *data, int ATTRIBUTE_UNUSED depth) { size_t len = sb->st_size; - void *the_module, *ptr; + void *the_module; + char *ptr; int fd; char *depends, *deps; + if (strrstr(fname, ".ko") == NULL) /* not a module */ + goto skip; + /*XXX: FIXME: does not handle compressed modules! * There should be a function that looks at the extension and sets up * open_transformer for us. */ - if (last_char_is(fname, 'o') == NULL) /* not a module */ - goto skip; - fd = xopen(fname, O_RDONLY); the_module = mmap(NULL, len, PROT_READ, MAP_SHARED #if defined MAP_POPULATE @@ -64,43 +68,36 @@ static int fileAction(const char *fname, struct stat *sb, //bb_info_msg("fname='%s'", fname + G.moddir_base_len); do { /* search for a 'd' */ - ptr = memchr(ptr, 'd', len - (ptr - the_module)); + ptr = memchr(ptr, 'd', len - (ptr - (char*)the_module)); if (ptr == NULL) /* no d left, done */ - goto done; - if (memcmp(ptr, "depends=", sizeof("depends=")-1) == 0) + goto none; + if (strncmp(ptr, "depends=", sizeof("depends=")-1) == 0) break; ++ptr; } while (1); deps = depends = xstrdup (ptr + sizeof("depends=")-1); //bb_info_msg(" depends='%s'", depends); - while (*deps) { + while (deps) { llist_t * _lst = G.lst; - char *buf1; - - ptr = strchr(deps, ','); - if (ptr != NULL) - *(char*)ptr = '\0'; - /* remember the length of the current dependency plus eventual 0 byte */ - len = strlen(deps) + (ptr != NULL); - buf1 = xasprintf("/%s.", deps); /* match the correct file */ + + ptr = strsep(&deps, ","); while (_lst) { - ptr = strstr(_lst->data, buf1); - if (ptr != NULL) + /* Compare the recorded filenames ignoring ".ko*" at the end. */ + char *tmp = bb_get_last_path_component_nostrip(_lst->data); + if (strncmp(ptr, tmp, strrstr(tmp, ".ko") - tmp) == 0) break; /* found it */ _lst = _lst->link; } - free(buf1); - if (_lst /*&& _lst->data*/) { -//bb_info_msg("[%s] -> '%s'", deps, _lst->data); + if (_lst) { +//bb_info_msg("[%s] -> '%s'", (char*)ptr, _lst->data); fprintf((FILE*)data, " %s", _lst->data); - deps += len; } } free(depends); fprintf((FILE*)data, "\n"); -done: + none: munmap(the_module, sb->st_size); -skip: + skip: return TRUE; } @@ -123,7 +120,7 @@ int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv) argv += optind; /* got a version to use? */ - if (*argv && (sscanf(*argv, "%u.%u.%u", &ret, &ret, &ret) == 3)) { + if (*argv && (sscanf(*argv, "%d.%d.%d", &ret, &ret, &ret) == 3)) { moddir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, *argv++); } else { struct utsname uts; @@ -131,7 +128,7 @@ int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv) bb_simple_perror_msg_and_die("uname"); moddir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, uts.release); } - /* if no modules are given on the command-line, -a is on per default */ + /* If no modules are given on the command-line, -a is on per default. */ option_mask32 |= *argv == NULL; if (option_mask32 & ARG_b) { @@ -151,15 +148,18 @@ int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv) free(chp); } ret = EXIT_SUCCESS; - /* have to do a full walk to collect all needed data */ + /* We have to do a full walk to collect all needed data. */ if (!recursive_action(moddir, ACTION_RECURSE, /* flags */ fill_lst, /* file action */ NULL, /* dir action */ NULL, /* user data */ - 0)) { - ret = EXIT_FAILURE; - } else + 0)) { /* depth */ + if (ENABLE_FEATURE_CLEAN_UP) + ret = EXIT_FAILURE; + else + return EXIT_FAILURE; + } do { chp = option_mask32 & ARG_a ? moddir : *argv++;