diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-01-12 22:12:22 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-01-12 22:12:22 +0000 |
commit | 35261159e6ccddcb36fce427d04b93e119c116c0 (patch) | |
tree | bf180c9d5f9e91c3df48f0a6dba55cb974227371 /modutils/depmod.c | |
parent | f478fde33ce182f8826dc498f1998a49bfa01fa2 (diff) | |
download | busybox-w32-35261159e6ccddcb36fce427d04b93e119c116c0.tar.gz busybox-w32-35261159e6ccddcb36fce427d04b93e119c116c0.tar.bz2 busybox-w32-35261159e6ccddcb36fce427d04b93e119c116c0.zip |
depmod: fix -b option (by timo.teras AT iki.fi)
function old new delta
xfreopen_write - 35 +35
parse_module 346 353 +7
depmod_main 553 546 -7
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 42/-7) Total: 35 bytes
Diffstat (limited to 'modutils/depmod.c')
-rw-r--r-- | modutils/depmod.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/modutils/depmod.c b/modutils/depmod.c index a4474d5e4..7f3e1d8a6 100644 --- a/modutils/depmod.c +++ b/modutils/depmod.c | |||
@@ -33,7 +33,7 @@ typedef struct module_info { | |||
33 | enum { | 33 | enum { |
34 | ARG_a = (1<<0), /* All modules, ignore mods in argv */ | 34 | ARG_a = (1<<0), /* All modules, ignore mods in argv */ |
35 | ARG_A = (1<<1), /* Only emit .ko that are newer than modules.dep file */ | 35 | ARG_A = (1<<1), /* Only emit .ko that are newer than modules.dep file */ |
36 | ARG_b = (1<<2), /* not /lib/modules/$(uname -r)/ but this base-dir */ | 36 | ARG_b = (1<<2), /* base directory when modules are in staging area */ |
37 | ARG_e = (1<<3), /* with -F, print unresolved symbols */ | 37 | ARG_e = (1<<3), /* with -F, print unresolved symbols */ |
38 | ARG_F = (1<<4), /* System.map that contains the symbols */ | 38 | ARG_F = (1<<4), /* System.map that contains the symbols */ |
39 | ARG_n = (1<<5) /* dry-run, print to stdout only */ | 39 | ARG_n = (1<<5) /* dry-run, print to stdout only */ |
@@ -57,7 +57,7 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb, | |||
57 | *first = info; | 57 | *first = info; |
58 | 58 | ||
59 | info->dnext = info->dprev = info; | 59 | info->dnext = info->dprev = info; |
60 | info->name = xstrdup(fname); | 60 | info->name = xasprintf("/%s", fname); |
61 | info->modname = filename2modname(fname, NULL); | 61 | info->modname = filename2modname(fname, NULL); |
62 | for (ptr = image; ptr < image + len - 10; ptr++) { | 62 | for (ptr = image; ptr < image + len - 10; ptr++) { |
63 | if (strncmp(ptr, "depends=", 8) == 0) { | 63 | if (strncmp(ptr, "depends=", 8) == 0) { |
@@ -123,44 +123,61 @@ static void order_dep_list(module_info *modules, module_info *start, | |||
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | static void xfreopen_write(const char *file, FILE *f) | ||
127 | { | ||
128 | if (freopen(file, "w", f) == NULL) | ||
129 | bb_perror_msg_and_die("can't open '%s'", file); | ||
130 | } | ||
131 | |||
126 | int depmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 132 | int depmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
127 | int depmod_main(int argc UNUSED_PARAM, char **argv) | 133 | int depmod_main(int argc UNUSED_PARAM, char **argv) |
128 | { | 134 | { |
129 | module_info *modules = NULL, *m, *dep; | 135 | module_info *modules = NULL, *m, *dep; |
130 | char *moddir_base = (char *)CONFIG_DEFAULT_MODULES_DIR; | 136 | const char *moddir_base = "/"; |
137 | char *moddir, *version; | ||
138 | struct utsname uts; | ||
131 | int tmp; | 139 | int tmp; |
132 | 140 | ||
133 | getopt32(argv, "aAb:eF:n", &moddir_base, NULL); | 141 | getopt32(argv, "aAb:eF:n", &moddir_base, NULL); |
134 | argv += optind; | 142 | argv += optind; |
135 | 143 | ||
136 | /* goto modules location */ | 144 | /* goto modules location */ |
145 | xchdir(moddir_base); | ||
137 | 146 | ||
138 | /* If a version is provided, then that kernel version's module directory | 147 | /* If a version is provided, then that kernel version's module directory |
139 | * is used, rather than the current kernel version (as returned by | 148 | * is used, rather than the current kernel version (as returned by |
140 | * "uname -r"). */ | 149 | * "uname -r"). */ |
141 | xchdir(moddir_base); | 150 | if (*argv && sscanf(*argv, "%d.%d.%d", &tmp, &tmp, &tmp) == 3) { |
142 | if (*argv && (sscanf(*argv, "%d.%d.%d", &tmp, &tmp, &tmp) == 3)) { | 151 | version = *argv++; |
143 | xchdir(*argv++); | ||
144 | } else { | 152 | } else { |
145 | struct utsname uts; | ||
146 | uname(&uts); | 153 | uname(&uts); |
147 | xchdir(uts.release); | 154 | version = uts.release; |
148 | } | 155 | } |
149 | /* If no modules are given on the command-line, -a is on per default. */ | 156 | moddir = concat_path_file(&CONFIG_DEFAULT_MODULES_DIR[1], version); |
150 | option_mask32 |= *argv == NULL; | ||
151 | 157 | ||
152 | /* Scan modules */ | 158 | /* Scan modules */ |
153 | moddir_base = xrealloc_getcwd_or_warn(NULL); | 159 | if (*argv) { |
154 | do { | 160 | char *modfile; |
155 | recursive_action((option_mask32 & ARG_a) ? moddir_base : *argv, | 161 | struct stat sb; |
156 | ACTION_RECURSE, parse_module, NULL, &modules, 0); | 162 | do { |
157 | } while (!(option_mask32 & ARG_a) && *(++argv)); | 163 | modfile = concat_path_file(moddir, *argv); |
164 | xstat(modfile, &sb); | ||
165 | parse_module(modfile, &sb, &modules, 0); | ||
166 | free(modfile); | ||
167 | } while (*(++argv)); | ||
168 | } else { | ||
169 | recursive_action(moddir, ACTION_RECURSE, | ||
170 | parse_module, NULL, &modules, 0); | ||
171 | } | ||
172 | |||
173 | /* Prepare for writing out the dep files */ | ||
174 | xchdir(moddir); | ||
158 | if (ENABLE_FEATURE_CLEAN_UP) | 175 | if (ENABLE_FEATURE_CLEAN_UP) |
159 | free(moddir_base); | 176 | free(moddir); |
160 | 177 | ||
161 | /* Generate dependency and alias files */ | 178 | /* Generate dependency and alias files */ |
162 | if (!(option_mask32 & ARG_n)) | 179 | if (!(option_mask32 & ARG_n)) |
163 | freopen(CONFIG_DEFAULT_DEPMOD_FILE, "w", stdout); | 180 | xfreopen_write(CONFIG_DEFAULT_DEPMOD_FILE, stdout); |
164 | for (m = modules; m != NULL; m = m->next) { | 181 | for (m = modules; m != NULL; m = m->next) { |
165 | printf("%s:", m->name); | 182 | printf("%s:", m->name); |
166 | 183 | ||
@@ -174,12 +191,12 @@ int depmod_main(int argc UNUSED_PARAM, char **argv) | |||
174 | dep->dprev->dnext = dep->dnext; | 191 | dep->dprev->dnext = dep->dnext; |
175 | dep->dnext = dep->dprev = dep; | 192 | dep->dnext = dep->dprev = dep; |
176 | } | 193 | } |
177 | puts(""); | 194 | bb_putchar('\n'); |
178 | } | 195 | } |
179 | 196 | ||
180 | #if ENABLE_FEATURE_MODUTILS_ALIAS | 197 | #if ENABLE_FEATURE_MODUTILS_ALIAS |
181 | if (!(option_mask32 & ARG_n)) | 198 | if (!(option_mask32 & ARG_n)) |
182 | freopen("modules.alias", "w", stdout); | 199 | xfreopen_write("modules.alias", stdout); |
183 | for (m = modules; m != NULL; m = m->next) { | 200 | for (m = modules; m != NULL; m = m->next) { |
184 | while (m->aliases) { | 201 | while (m->aliases) { |
185 | printf("alias %s %s\n", | 202 | printf("alias %s %s\n", |
@@ -190,7 +207,7 @@ int depmod_main(int argc UNUSED_PARAM, char **argv) | |||
190 | #endif | 207 | #endif |
191 | #if ENABLE_FEATURE_MODUTILS_SYMBOLS | 208 | #if ENABLE_FEATURE_MODUTILS_SYMBOLS |
192 | if (!(option_mask32 & ARG_n)) | 209 | if (!(option_mask32 & ARG_n)) |
193 | freopen("modules.symbols", "w", stdout); | 210 | xfreopen_write("modules.symbols", stdout); |
194 | for (m = modules; m != NULL; m = m->next) { | 211 | for (m = modules; m != NULL; m = m->next) { |
195 | while (m->symbols) { | 212 | while (m->symbols) { |
196 | printf("alias symbol:%s %s\n", | 213 | printf("alias symbol:%s %s\n", |