- misc. improvements and shrinkage
This commit is contained in:
@@ -18,8 +18,8 @@
|
|||||||
* for each depends, look through our list of full paths and emit if found
|
* for each depends, look through our list of full paths and emit if found
|
||||||
*/
|
*/
|
||||||
struct globals {
|
struct globals {
|
||||||
llist_t *lst;
|
llist_t *lst; /* modules without their corresponding extension */
|
||||||
unsigned moddir_base_len;
|
size_t moddir_base_len; /* length of the "-b basedir" */
|
||||||
};
|
};
|
||||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||||
/* We have to zero it out because of NOEXEC */
|
/* 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,
|
static int fill_lst(const char *modulename, struct stat ATTRIBUTE_UNUSED *sb,
|
||||||
void ATTRIBUTE_UNUSED *data, int ATTRIBUTE_UNUSED depth)
|
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));
|
llist_add_to(&G.lst, xstrdup(modulename + G.moddir_base_len));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -37,17 +40,18 @@ static int fileAction(const char *fname, struct stat *sb,
|
|||||||
void *data, int ATTRIBUTE_UNUSED depth)
|
void *data, int ATTRIBUTE_UNUSED depth)
|
||||||
{
|
{
|
||||||
size_t len = sb->st_size;
|
size_t len = sb->st_size;
|
||||||
void *the_module, *ptr;
|
void *the_module;
|
||||||
|
char *ptr;
|
||||||
int fd;
|
int fd;
|
||||||
char *depends, *deps;
|
char *depends, *deps;
|
||||||
|
|
||||||
|
if (strrstr(fname, ".ko") == NULL) /* not a module */
|
||||||
|
goto skip;
|
||||||
|
|
||||||
/*XXX: FIXME: does not handle compressed modules!
|
/*XXX: FIXME: does not handle compressed modules!
|
||||||
* There should be a function that looks at the extension and sets up
|
* There should be a function that looks at the extension and sets up
|
||||||
* open_transformer for us.
|
* open_transformer for us.
|
||||||
*/
|
*/
|
||||||
if (last_char_is(fname, 'o') == NULL) /* not a module */
|
|
||||||
goto skip;
|
|
||||||
|
|
||||||
fd = xopen(fname, O_RDONLY);
|
fd = xopen(fname, O_RDONLY);
|
||||||
the_module = mmap(NULL, len, PROT_READ, MAP_SHARED
|
the_module = mmap(NULL, len, PROT_READ, MAP_SHARED
|
||||||
#if defined MAP_POPULATE
|
#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);
|
//bb_info_msg("fname='%s'", fname + G.moddir_base_len);
|
||||||
do {
|
do {
|
||||||
/* search for a 'd' */
|
/* 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 */
|
if (ptr == NULL) /* no d left, done */
|
||||||
goto done;
|
goto none;
|
||||||
if (memcmp(ptr, "depends=", sizeof("depends=")-1) == 0)
|
if (strncmp(ptr, "depends=", sizeof("depends=")-1) == 0)
|
||||||
break;
|
break;
|
||||||
++ptr;
|
++ptr;
|
||||||
} while (1);
|
} while (1);
|
||||||
deps = depends = xstrdup (ptr + sizeof("depends=")-1);
|
deps = depends = xstrdup (ptr + sizeof("depends=")-1);
|
||||||
//bb_info_msg(" depends='%s'", depends);
|
//bb_info_msg(" depends='%s'", depends);
|
||||||
while (*deps) {
|
while (deps) {
|
||||||
llist_t * _lst = G.lst;
|
llist_t * _lst = G.lst;
|
||||||
char *buf1;
|
|
||||||
|
|
||||||
ptr = strchr(deps, ',');
|
ptr = strsep(&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 */
|
|
||||||
while (_lst) {
|
while (_lst) {
|
||||||
ptr = strstr(_lst->data, buf1);
|
/* Compare the recorded filenames ignoring ".ko*" at the end. */
|
||||||
if (ptr != NULL)
|
char *tmp = bb_get_last_path_component_nostrip(_lst->data);
|
||||||
|
if (strncmp(ptr, tmp, strrstr(tmp, ".ko") - tmp) == 0)
|
||||||
break; /* found it */
|
break; /* found it */
|
||||||
_lst = _lst->link;
|
_lst = _lst->link;
|
||||||
}
|
}
|
||||||
free(buf1);
|
if (_lst) {
|
||||||
if (_lst /*&& _lst->data*/) {
|
//bb_info_msg("[%s] -> '%s'", (char*)ptr, _lst->data);
|
||||||
//bb_info_msg("[%s] -> '%s'", deps, _lst->data);
|
|
||||||
fprintf((FILE*)data, " %s", _lst->data);
|
fprintf((FILE*)data, " %s", _lst->data);
|
||||||
deps += len;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(depends);
|
free(depends);
|
||||||
fprintf((FILE*)data, "\n");
|
fprintf((FILE*)data, "\n");
|
||||||
done:
|
none:
|
||||||
munmap(the_module, sb->st_size);
|
munmap(the_module, sb->st_size);
|
||||||
skip:
|
skip:
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +120,7 @@ int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv)
|
|||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
/* got a version to use? */
|
/* 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++);
|
moddir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, *argv++);
|
||||||
} else {
|
} else {
|
||||||
struct utsname uts;
|
struct utsname uts;
|
||||||
@@ -131,7 +128,7 @@ int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv)
|
|||||||
bb_simple_perror_msg_and_die("uname");
|
bb_simple_perror_msg_and_die("uname");
|
||||||
moddir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, uts.release);
|
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;
|
option_mask32 |= *argv == NULL;
|
||||||
|
|
||||||
if (option_mask32 & ARG_b) {
|
if (option_mask32 & ARG_b) {
|
||||||
@@ -151,15 +148,18 @@ int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv)
|
|||||||
free(chp);
|
free(chp);
|
||||||
}
|
}
|
||||||
ret = EXIT_SUCCESS;
|
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,
|
if (!recursive_action(moddir,
|
||||||
ACTION_RECURSE, /* flags */
|
ACTION_RECURSE, /* flags */
|
||||||
fill_lst, /* file action */
|
fill_lst, /* file action */
|
||||||
NULL, /* dir action */
|
NULL, /* dir action */
|
||||||
NULL, /* user data */
|
NULL, /* user data */
|
||||||
0)) {
|
0)) { /* depth */
|
||||||
ret = EXIT_FAILURE;
|
if (ENABLE_FEATURE_CLEAN_UP)
|
||||||
} else
|
ret = EXIT_FAILURE;
|
||||||
|
else
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
chp = option_mask32 & ARG_a ? moddir : *argv++;
|
chp = option_mask32 & ARG_a ? moddir : *argv++;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user