aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2008-05-28 14:20:20 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2008-05-28 14:20:20 +0000
commit634b0221088680153f4abe18db0504fda75a6d86 (patch)
treef84df94eab69bb6f6efeebe3d6ae54fc8d98a2b9
parent17282292c2259b130ef7833bdac97c8ce8bf5515 (diff)
downloadbusybox-w32-634b0221088680153f4abe18db0504fda75a6d86.tar.gz
busybox-w32-634b0221088680153f4abe18db0504fda75a6d86.tar.bz2
busybox-w32-634b0221088680153f4abe18db0504fda75a6d86.zip
- misc. improvements and shrinkage
-rw-r--r--modutils/depmod.c66
1 files changed, 33 insertions, 33 deletions
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 @@
18 * for each depends, look through our list of full paths and emit if found 18 * for each depends, look through our list of full paths and emit if found
19 */ 19 */
20struct globals { 20struct globals {
21 llist_t *lst; 21 llist_t *lst; /* modules without their corresponding extension */
22 unsigned moddir_base_len; 22 size_t moddir_base_len; /* length of the "-b basedir" */
23}; 23};
24#define G (*(struct globals*)&bb_common_bufsiz1) 24#define G (*(struct globals*)&bb_common_bufsiz1)
25/* We have to zero it out because of NOEXEC */ 25/* We have to zero it out because of NOEXEC */
@@ -28,7 +28,10 @@ struct globals {
28static int fill_lst(const char *modulename, struct stat ATTRIBUTE_UNUSED *sb, 28static int fill_lst(const char *modulename, struct stat ATTRIBUTE_UNUSED *sb,
29 void ATTRIBUTE_UNUSED *data, int ATTRIBUTE_UNUSED depth) 29 void ATTRIBUTE_UNUSED *data, int ATTRIBUTE_UNUSED depth)
30{ 30{
31 if (last_char_is(modulename, 'o') != NULL) /* it is a module, remember it */ 31 /* We get a file here. If the file does not have ".ko" but an
32 * intermittent dentry has, it's just their fault.
33 */
34 if (strrstr(modulename, ".ko") != NULL)
32 llist_add_to(&G.lst, xstrdup(modulename + G.moddir_base_len)); 35 llist_add_to(&G.lst, xstrdup(modulename + G.moddir_base_len));
33 return TRUE; 36 return TRUE;
34} 37}
@@ -37,17 +40,18 @@ static int fileAction(const char *fname, struct stat *sb,
37 void *data, int ATTRIBUTE_UNUSED depth) 40 void *data, int ATTRIBUTE_UNUSED depth)
38{ 41{
39 size_t len = sb->st_size; 42 size_t len = sb->st_size;
40 void *the_module, *ptr; 43 void *the_module;
44 char *ptr;
41 int fd; 45 int fd;
42 char *depends, *deps; 46 char *depends, *deps;
43 47
48 if (strrstr(fname, ".ko") == NULL) /* not a module */
49 goto skip;
50
44/*XXX: FIXME: does not handle compressed modules! 51/*XXX: FIXME: does not handle compressed modules!
45 * There should be a function that looks at the extension and sets up 52 * There should be a function that looks at the extension and sets up
46 * open_transformer for us. 53 * open_transformer for us.
47 */ 54 */
48 if (last_char_is(fname, 'o') == NULL) /* not a module */
49 goto skip;
50
51 fd = xopen(fname, O_RDONLY); 55 fd = xopen(fname, O_RDONLY);
52 the_module = mmap(NULL, len, PROT_READ, MAP_SHARED 56 the_module = mmap(NULL, len, PROT_READ, MAP_SHARED
53#if defined MAP_POPULATE 57#if defined MAP_POPULATE
@@ -64,43 +68,36 @@ static int fileAction(const char *fname, struct stat *sb,
64//bb_info_msg("fname='%s'", fname + G.moddir_base_len); 68//bb_info_msg("fname='%s'", fname + G.moddir_base_len);
65 do { 69 do {
66 /* search for a 'd' */ 70 /* search for a 'd' */
67 ptr = memchr(ptr, 'd', len - (ptr - the_module)); 71 ptr = memchr(ptr, 'd', len - (ptr - (char*)the_module));
68 if (ptr == NULL) /* no d left, done */ 72 if (ptr == NULL) /* no d left, done */
69 goto done; 73 goto none;
70 if (memcmp(ptr, "depends=", sizeof("depends=")-1) == 0) 74 if (strncmp(ptr, "depends=", sizeof("depends=")-1) == 0)
71 break; 75 break;
72 ++ptr; 76 ++ptr;
73 } while (1); 77 } while (1);
74 deps = depends = xstrdup (ptr + sizeof("depends=")-1); 78 deps = depends = xstrdup (ptr + sizeof("depends=")-1);
75//bb_info_msg(" depends='%s'", depends); 79//bb_info_msg(" depends='%s'", depends);
76 while (*deps) { 80 while (deps) {
77 llist_t * _lst = G.lst; 81 llist_t * _lst = G.lst;
78 char *buf1; 82
79 83 ptr = strsep(&deps, ",");
80 ptr = strchr(deps, ',');
81 if (ptr != NULL)
82 *(char*)ptr = '\0';
83 /* remember the length of the current dependency plus eventual 0 byte */
84 len = strlen(deps) + (ptr != NULL);
85 buf1 = xasprintf("/%s.", deps); /* match the correct file */
86 while (_lst) { 84 while (_lst) {
87 ptr = strstr(_lst->data, buf1); 85 /* Compare the recorded filenames ignoring ".ko*" at the end. */
88 if (ptr != NULL) 86 char *tmp = bb_get_last_path_component_nostrip(_lst->data);
87 if (strncmp(ptr, tmp, strrstr(tmp, ".ko") - tmp) == 0)
89 break; /* found it */ 88 break; /* found it */
90 _lst = _lst->link; 89 _lst = _lst->link;
91 } 90 }
92 free(buf1); 91 if (_lst) {
93 if (_lst /*&& _lst->data*/) { 92//bb_info_msg("[%s] -> '%s'", (char*)ptr, _lst->data);
94//bb_info_msg("[%s] -> '%s'", deps, _lst->data);
95 fprintf((FILE*)data, " %s", _lst->data); 93 fprintf((FILE*)data, " %s", _lst->data);
96 deps += len;
97 } 94 }
98 } 95 }
99 free(depends); 96 free(depends);
100 fprintf((FILE*)data, "\n"); 97 fprintf((FILE*)data, "\n");
101done: 98 none:
102 munmap(the_module, sb->st_size); 99 munmap(the_module, sb->st_size);
103skip: 100 skip:
104 return TRUE; 101 return TRUE;
105} 102}
106 103
@@ -123,7 +120,7 @@ int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv)
123 argv += optind; 120 argv += optind;
124 121
125 /* got a version to use? */ 122 /* got a version to use? */
126 if (*argv && (sscanf(*argv, "%u.%u.%u", &ret, &ret, &ret) == 3)) { 123 if (*argv && (sscanf(*argv, "%d.%d.%d", &ret, &ret, &ret) == 3)) {
127 moddir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, *argv++); 124 moddir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, *argv++);
128 } else { 125 } else {
129 struct utsname uts; 126 struct utsname uts;
@@ -131,7 +128,7 @@ int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv)
131 bb_simple_perror_msg_and_die("uname"); 128 bb_simple_perror_msg_and_die("uname");
132 moddir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, uts.release); 129 moddir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, uts.release);
133 } 130 }
134 /* if no modules are given on the command-line, -a is on per default */ 131 /* If no modules are given on the command-line, -a is on per default. */
135 option_mask32 |= *argv == NULL; 132 option_mask32 |= *argv == NULL;
136 133
137 if (option_mask32 & ARG_b) { 134 if (option_mask32 & ARG_b) {
@@ -151,15 +148,18 @@ int depmod_main(int ATTRIBUTE_UNUSED argc, char **argv)
151 free(chp); 148 free(chp);
152 } 149 }
153 ret = EXIT_SUCCESS; 150 ret = EXIT_SUCCESS;
154 /* have to do a full walk to collect all needed data */ 151 /* We have to do a full walk to collect all needed data. */
155 if (!recursive_action(moddir, 152 if (!recursive_action(moddir,
156 ACTION_RECURSE, /* flags */ 153 ACTION_RECURSE, /* flags */
157 fill_lst, /* file action */ 154 fill_lst, /* file action */
158 NULL, /* dir action */ 155 NULL, /* dir action */
159 NULL, /* user data */ 156 NULL, /* user data */
160 0)) { 157 0)) { /* depth */
161 ret = EXIT_FAILURE; 158 if (ENABLE_FEATURE_CLEAN_UP)
162 } else 159 ret = EXIT_FAILURE;
160 else
161 return EXIT_FAILURE;
162 }
163 do { 163 do {
164 chp = option_mask32 & ARG_a ? moddir : *argv++; 164 chp = option_mask32 & ARG_a ? moddir : *argv++;
165 165