diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-11-02 23:31:10 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-11-02 23:31:10 +0000 |
commit | b68979aefa0efb519e6af02deba082e6b4180043 (patch) | |
tree | b16d64f31b629e54c70d30abbd98f3b4f46d7cd4 /modutils/modprobe.c | |
parent | 9d1afdb571e0ba3053616d74edc99a68325ef5e9 (diff) | |
download | busybox-w32-b68979aefa0efb519e6af02deba082e6b4180043.tar.gz busybox-w32-b68979aefa0efb519e6af02deba082e6b4180043.tar.bz2 busybox-w32-b68979aefa0efb519e6af02deba082e6b4180043.zip |
insmod: code shrink, stop exporting insmod_ng_main.
function old new delta
add_ksymoops_symbols - 421 +421
static.section_names 20 40 +20
lsmod_main 425 424 -1
set_tainted 153 150 -3
main_opts 4 - -4
obj_symbol_patch 47 42 -5
obj_string_patch 144 139 -5
already_loaded 144 138 -6
check_dep 348 341 -7
append_option 75 68 -7
obj_allocate_commons 515 501 -14
new_process_module_arguments 1039 1018 -21
arch_new_symbol 31 9 -22
check_module_name_match 85 61 -24
obj_create_alloced_section 164 136 -28
include_conf 930 902 -28
modprobe_main 1643 1535 -108
obj_load 924 777 -147
insmod_ng_main 245 - -245
insmod_main 4122 3794 -328
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 1/16 up/down: 441/-1003) Total: -562 bytes
text data bss dec hex filename
776020 974 9420 786414 bffee busybox_old
775384 974 9420 785778 bfd72 busybox_unstripped
Diffstat (limited to 'modutils/modprobe.c')
-rw-r--r-- | modutils/modprobe.c | 270 |
1 files changed, 134 insertions, 136 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index a67ddea9b..f7d193a05 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
@@ -15,6 +15,8 @@ | |||
15 | #include <sys/utsname.h> | 15 | #include <sys/utsname.h> |
16 | #include <fnmatch.h> | 16 | #include <fnmatch.h> |
17 | 17 | ||
18 | #define line_buffer bb_common_bufsiz1 | ||
19 | |||
18 | struct mod_opt_t { /* one-way list of options to pass to a module */ | 20 | struct mod_opt_t { /* one-way list of options to pass to a module */ |
19 | char * m_opt_val; | 21 | char * m_opt_val; |
20 | struct mod_opt_t * m_next; | 22 | struct mod_opt_t * m_next; |
@@ -48,7 +50,7 @@ struct mod_list_t { /* two-way list of modules to process */ | |||
48 | 50 | ||
49 | static struct dep_t *depend; | 51 | static struct dep_t *depend; |
50 | 52 | ||
51 | #define main_options "acdklnqrst:vVC:" | 53 | #define MAIN_OPT_STR "acdklnqrst:vVC:" |
52 | #define INSERT_ALL 1 /* a */ | 54 | #define INSERT_ALL 1 /* a */ |
53 | #define DUMP_CONF_EXIT 2 /* c */ | 55 | #define DUMP_CONF_EXIT 2 /* c */ |
54 | #define D_OPT_IGNORED 4 /* d */ | 56 | #define D_OPT_IGNORED 4 /* d */ |
@@ -63,14 +65,12 @@ static struct dep_t *depend; | |||
63 | #define VERSION_ONLY 2048 /* V */ | 65 | #define VERSION_ONLY 2048 /* V */ |
64 | #define CONFIG_FILE 4096 /* C */ | 66 | #define CONFIG_FILE 4096 /* C */ |
65 | 67 | ||
66 | #define autoclean (main_opts & AUTOCLEAN_FLG) | 68 | #define autoclean (option_mask32 & AUTOCLEAN_FLG) |
67 | #define show_only (main_opts & SHOW_ONLY) | 69 | #define show_only (option_mask32 & SHOW_ONLY) |
68 | #define quiet (main_opts & QUIET) | 70 | #define quiet (option_mask32 & QUIET) |
69 | #define remove_opt (main_opts & REMOVE_OPT) | 71 | #define remove_opt (option_mask32 & REMOVE_OPT) |
70 | #define do_syslog (main_opts & DO_SYSLOG) | 72 | #define do_syslog (option_mask32 & DO_SYSLOG) |
71 | #define verbose (main_opts & VERBOSE) | 73 | #define verbose (option_mask32 & VERBOSE) |
72 | |||
73 | static int main_opts; | ||
74 | 74 | ||
75 | static int parse_tag_value(char *buffer, char **ptag, char **pvalue) | 75 | static int parse_tag_value(char *buffer, char **ptag, char **pvalue) |
76 | { | 76 | { |
@@ -78,12 +78,15 @@ static int parse_tag_value(char *buffer, char **ptag, char **pvalue) | |||
78 | 78 | ||
79 | buffer = skip_whitespace(buffer); | 79 | buffer = skip_whitespace(buffer); |
80 | tag = value = buffer; | 80 | tag = value = buffer; |
81 | while (!isspace(*value)) | 81 | while (!isspace(*value)) { |
82 | if (!*value) return 0; | 82 | if (!*value) |
83 | else value++; | 83 | return 0; |
84 | *value++ = 0; | 84 | value++; |
85 | } | ||
86 | *value++ = '\0'; | ||
85 | value = skip_whitespace(value); | 87 | value = skip_whitespace(value); |
86 | if (!*value) return 0; | 88 | if (!*value) |
89 | return 0; | ||
87 | 90 | ||
88 | *ptag = tag; | 91 | *ptag = tag; |
89 | *pvalue = value; | 92 | *pvalue = value; |
@@ -102,14 +105,14 @@ static struct mod_opt_t *append_option(struct mod_opt_t *opt_list, char *opt) | |||
102 | while (ol->m_next) { | 105 | while (ol->m_next) { |
103 | ol = ol->m_next; | 106 | ol = ol->m_next; |
104 | } | 107 | } |
105 | ol->m_next = xmalloc(sizeof(struct mod_opt_t)); | 108 | ol->m_next = xzalloc(sizeof(struct mod_opt_t)); |
106 | ol = ol->m_next; | 109 | ol = ol->m_next; |
107 | } else { | 110 | } else { |
108 | ol = opt_list = xmalloc(sizeof(struct mod_opt_t)); | 111 | ol = opt_list = xzalloc(sizeof(struct mod_opt_t)); |
109 | } | 112 | } |
110 | 113 | ||
111 | ol->m_opt_val = xstrdup(opt); | 114 | ol->m_opt_val = xstrdup(opt); |
112 | ol->m_next = NULL; | 115 | /*ol->m_next = NULL; - done by xzalloc*/ |
113 | 116 | ||
114 | return opt_list; | 117 | return opt_list; |
115 | } | 118 | } |
@@ -190,7 +193,8 @@ static char *parse_command_string(char *src, char **dst) | |||
190 | case '0': | 193 | case '0': |
191 | /* We escaped a special character. For now, keep | 194 | /* We escaped a special character. For now, keep |
192 | * both the back-slash and the following char. */ | 195 | * both the back-slash and the following char. */ |
193 | tmp_str++; src++; | 196 | tmp_str++; |
197 | src++; | ||
194 | break; | 198 | break; |
195 | default: | 199 | default: |
196 | /* We escaped a space or a single or double quote, | 200 | /* We escaped a space or a single or double quote, |
@@ -242,12 +246,12 @@ static void include_conf(struct dep_t **first, struct dep_t **current, char *buf | |||
242 | 246 | ||
243 | p = strchr(buffer, '#'); | 247 | p = strchr(buffer, '#'); |
244 | if (p) | 248 | if (p) |
245 | *p = 0; | 249 | *p = '\0'; |
246 | 250 | ||
247 | l = strlen(buffer); | 251 | l = strlen(buffer); |
248 | 252 | ||
249 | while (l && isspace(buffer[l-1])) { | 253 | while (l && isspace(buffer[l-1])) { |
250 | buffer[l-1] = 0; | 254 | buffer[l-1] = '\0'; |
251 | l--; | 255 | l--; |
252 | } | 256 | } |
253 | 257 | ||
@@ -256,66 +260,68 @@ static void include_conf(struct dep_t **first, struct dep_t **current, char *buf | |||
256 | continue; | 260 | continue; |
257 | } | 261 | } |
258 | 262 | ||
259 | if (!continuation_line) { | 263 | if (continuation_line) |
260 | if ((strncmp(buffer, "alias", 5) == 0) && isspace(buffer[5])) { | 264 | continue; |
261 | char *alias, *mod; | ||
262 | 265 | ||
263 | if (parse_tag_value(buffer + 6, &alias, &mod)) { | 266 | if ((strncmp(buffer, "alias", 5) == 0) && isspace(buffer[5])) { |
264 | /* handle alias as a module dependent on the aliased module */ | 267 | char *alias, *mod; |
265 | if (!*current) { | ||
266 | (*first) = (*current) = xzalloc(sizeof(struct dep_t)); | ||
267 | } else { | ||
268 | (*current)->m_next = xzalloc(sizeof(struct dep_t)); | ||
269 | (*current) = (*current)->m_next; | ||
270 | } | ||
271 | (*current)->m_name = xstrdup(alias); | ||
272 | (*current)->m_isalias = 1; | ||
273 | 268 | ||
274 | if ((strcmp(mod, "off") == 0) || (strcmp(mod, "null") == 0)) { | 269 | if (parse_tag_value(buffer + 6, &alias, &mod)) { |
275 | (*current)->m_depcnt = 0; | 270 | /* handle alias as a module dependent on the aliased module */ |
276 | (*current)->m_deparr = 0; | 271 | if (!*current) { |
277 | } else { | 272 | (*first) = (*current) = xzalloc(sizeof(struct dep_t)); |
278 | (*current)->m_depcnt = 1; | 273 | } else { |
279 | (*current)->m_deparr = xmalloc(1 * sizeof(char *)); | 274 | (*current)->m_next = xzalloc(sizeof(struct dep_t)); |
280 | (*current)->m_deparr[0] = xstrdup(mod); | 275 | (*current) = (*current)->m_next; |
281 | } | ||
282 | (*current)->m_next = 0; | ||
283 | } | 276 | } |
284 | } else if ((strncmp(buffer, "options", 7) == 0) && isspace(buffer[7])) { | 277 | (*current)->m_name = xstrdup(alias); |
285 | char *mod, *opt; | 278 | (*current)->m_isalias = 1; |
286 | |||
287 | /* split the line in the module/alias name, and options */ | ||
288 | if (parse_tag_value(buffer + 8, &mod, &opt)) { | ||
289 | struct dep_t *dt; | ||
290 | 279 | ||
291 | /* find the corresponding module */ | 280 | if ((strcmp(mod, "off") == 0) || (strcmp(mod, "null") == 0)) { |
292 | for (dt = *first; dt; dt = dt->m_next) { | 281 | /*(*current)->m_depcnt = 0; - done by xzalloc */ |
293 | if (strcmp(dt->m_name, mod) == 0) | 282 | /*(*current)->m_deparr = 0;*/ |
294 | break; | 283 | } else { |
295 | } | 284 | (*current)->m_depcnt = 1; |
296 | if (dt) { | 285 | (*current)->m_deparr = xmalloc(sizeof(char *)); |
297 | if (ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS) { | 286 | (*current)->m_deparr[0] = xstrdup(mod); |
298 | char* new_opt = NULL; | ||
299 | while ((opt = parse_command_string(opt, &new_opt))) { | ||
300 | dt->m_options = append_option(dt->m_options, new_opt); | ||
301 | } | ||
302 | } else { | ||
303 | dt->m_options = append_option(dt->m_options, opt); | ||
304 | } | ||
305 | } | ||
306 | } | 287 | } |
307 | } else if ((strncmp(buffer, "include", 7) == 0) && isspace(buffer[7])) { | 288 | /*(*current)->m_next = NULL; - done by xzalloc */ |
308 | int fdi; char *filename; | 289 | } |
290 | } else if ((strncmp(buffer, "options", 7) == 0) && isspace(buffer[7])) { | ||
291 | char *mod, *opt; | ||
309 | 292 | ||
310 | filename = skip_whitespace(buffer + 8); | 293 | /* split the line in the module/alias name, and options */ |
294 | if (parse_tag_value(buffer + 8, &mod, &opt)) { | ||
295 | struct dep_t *dt; | ||
311 | 296 | ||
312 | if ((fdi = open(filename, O_RDONLY)) >= 0) { | 297 | /* find the corresponding module */ |
313 | include_conf(first, current, buffer, buflen, fdi); | 298 | for (dt = *first; dt; dt = dt->m_next) { |
314 | close(fdi); | 299 | if (strcmp(dt->m_name, mod) == 0) |
300 | break; | ||
315 | } | 301 | } |
302 | if (dt) { | ||
303 | if (ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS) { | ||
304 | char* new_opt = NULL; | ||
305 | while ((opt = parse_command_string(opt, &new_opt))) { | ||
306 | dt->m_options = append_option(dt->m_options, new_opt); | ||
307 | } | ||
308 | } else { | ||
309 | dt->m_options = append_option(dt->m_options, opt); | ||
310 | } | ||
311 | } | ||
312 | } | ||
313 | } else if ((strncmp(buffer, "include", 7) == 0) && isspace(buffer[7])) { | ||
314 | int fdi; | ||
315 | char *filename; | ||
316 | |||
317 | filename = skip_whitespace(buffer + 8); | ||
318 | fdi = open(filename, O_RDONLY); | ||
319 | if (fdi >= 0) { | ||
320 | include_conf(first, current, buffer, buflen, fdi); | ||
321 | close(fdi); | ||
316 | } | 322 | } |
317 | } | 323 | } |
318 | } | 324 | } /* while (reads(...)) */ |
319 | } | 325 | } |
320 | 326 | ||
321 | /* | 327 | /* |
@@ -327,9 +333,8 @@ static struct dep_t *build_dep(void) | |||
327 | { | 333 | { |
328 | int fd; | 334 | int fd; |
329 | struct utsname un; | 335 | struct utsname un; |
330 | struct dep_t *first = 0; | 336 | struct dep_t *first = NULL; |
331 | struct dep_t *current = 0; | 337 | struct dep_t *current = NULL; |
332 | char buffer[2048]; | ||
333 | char *filename; | 338 | char *filename; |
334 | int continuation_line = 0; | 339 | int continuation_line = 0; |
335 | int k_version; | 340 | int k_version; |
@@ -350,16 +355,16 @@ static struct dep_t *build_dep(void) | |||
350 | /* Ok, that didn't work. Fall back to looking in /lib/modules */ | 355 | /* Ok, that didn't work. Fall back to looking in /lib/modules */ |
351 | fd = open("/lib/modules/modules.dep", O_RDONLY); | 356 | fd = open("/lib/modules/modules.dep", O_RDONLY); |
352 | if (fd < 0) { | 357 | if (fd < 0) { |
353 | return 0; | 358 | bb_error_msg_and_die("cannot parse modules.dep"); |
354 | } | 359 | } |
355 | } | 360 | } |
356 | 361 | ||
357 | while (reads(fd, buffer, sizeof(buffer))) { | 362 | while (reads(fd, line_buffer, sizeof(line_buffer))) { |
358 | int l = strlen(buffer); | 363 | int l = strlen(line_buffer); |
359 | char *p = 0; | 364 | char *p = 0; |
360 | 365 | ||
361 | while (l > 0 && isspace(buffer[l-1])) { | 366 | while (l > 0 && isspace(line_buffer[l-1])) { |
362 | buffer[l-1] = 0; | 367 | line_buffer[l-1] = '\0'; |
363 | l--; | 368 | l--; |
364 | } | 369 | } |
365 | 370 | ||
@@ -371,7 +376,7 @@ static struct dep_t *build_dep(void) | |||
371 | /* Is this a new module dep description? */ | 376 | /* Is this a new module dep description? */ |
372 | if (!continuation_line) { | 377 | if (!continuation_line) { |
373 | /* find the dep beginning */ | 378 | /* find the dep beginning */ |
374 | char *col = strchr(buffer, ':'); | 379 | char *col = strchr(line_buffer, ':'); |
375 | char *dot = col; | 380 | char *dot = col; |
376 | 381 | ||
377 | if (col) { | 382 | if (col) { |
@@ -381,53 +386,52 @@ static struct dep_t *build_dep(void) | |||
381 | char *mod; | 386 | char *mod; |
382 | 387 | ||
383 | /* Find the beginning of the module file name */ | 388 | /* Find the beginning of the module file name */ |
384 | *col = 0; | 389 | *col = '\0'; |
385 | mods = bb_basename(buffer); | 390 | mods = bb_basename(line_buffer); |
386 | 391 | ||
387 | /* find the path of the module */ | 392 | /* find the path of the module */ |
388 | modpath = strchr(buffer, '/'); /* ... and this is the path */ | 393 | modpath = strchr(line_buffer, '/'); /* ... and this is the path */ |
389 | if (!modpath) | 394 | if (!modpath) |
390 | modpath = buffer; /* module with no path */ | 395 | modpath = line_buffer; /* module with no path */ |
391 | /* find the end of the module name in the file name */ | 396 | /* find the end of the module name in the file name */ |
392 | if (ENABLE_FEATURE_2_6_MODULES && | 397 | if (ENABLE_FEATURE_2_6_MODULES && |
393 | (k_version > 4) && (*(col-3) == '.') && | 398 | (k_version > 4) && (col[-3] == '.') && |
394 | (*(col-2) == 'k') && (*(col-1) == 'o')) | 399 | (col[-2] == 'k') && (col[-1] == 'o')) |
395 | dot = col - 3; | 400 | dot = col - 3; |
396 | else | 401 | else if ((col[-2] == '.') && (col[-1] == 'o')) |
397 | if ((*(col-2) == '.') && (*(col-1) == 'o')) | 402 | dot = col - 2; |
398 | dot = col - 2; | ||
399 | 403 | ||
400 | mod = xstrndup(mods, dot - mods); | 404 | mod = xstrndup(mods, dot - mods); |
401 | 405 | ||
402 | /* enqueue new module */ | 406 | /* enqueue new module */ |
403 | if (!current) { | 407 | if (!current) { |
404 | first = current = xmalloc(sizeof(struct dep_t)); | 408 | first = current = xzalloc(sizeof(struct dep_t)); |
405 | } else { | 409 | } else { |
406 | current->m_next = xmalloc(sizeof(struct dep_t)); | 410 | current->m_next = xzalloc(sizeof(struct dep_t)); |
407 | current = current->m_next; | 411 | current = current->m_next; |
408 | } | 412 | } |
409 | current->m_name = mod; | 413 | current->m_name = mod; |
410 | current->m_path = xstrdup(modpath); | 414 | current->m_path = xstrdup(modpath); |
411 | current->m_options = NULL; | 415 | /*current->m_options = NULL; - xzalloc did it*/ |
412 | current->m_isalias = 0; | 416 | /*current->m_isalias = 0;*/ |
413 | current->m_depcnt = 0; | 417 | /*current->m_depcnt = 0;*/ |
414 | current->m_deparr = 0; | 418 | /*current->m_deparr = 0;*/ |
415 | current->m_next = 0; | 419 | /*current->m_next = 0;*/ |
416 | 420 | ||
417 | p = col + 1; | 421 | p = col + 1; |
418 | } else | 422 | } else |
419 | /* this line is not a dep description */ | 423 | /* this line is not a dep description */ |
420 | p = 0; | 424 | p = NULL; |
421 | } else | 425 | } else |
422 | /* It's a dep description continuation */ | 426 | /* It's a dep description continuation */ |
423 | p = buffer; | 427 | p = line_buffer; |
424 | 428 | ||
425 | while (p && *p && isblank(*p)) | 429 | while (p && *p && isblank(*p)) |
426 | p++; | 430 | p++; |
427 | 431 | ||
428 | /* p points to the first dependable module; if NULL, no dependable module */ | 432 | /* p points to the first dependable module; if NULL, no dependable module */ |
429 | if (p && *p) { | 433 | if (p && *p) { |
430 | char *end = &buffer[l-1]; | 434 | char *end = &line_buffer[l-1]; |
431 | const char *deps; | 435 | const char *deps; |
432 | char *dep; | 436 | char *dep; |
433 | char *next; | 437 | char *next; |
@@ -440,7 +444,7 @@ static struct dep_t *build_dep(void) | |||
440 | /* search the end of the dependency */ | 444 | /* search the end of the dependency */ |
441 | next = strchr(p, ' '); | 445 | next = strchr(p, ' '); |
442 | if (next) { | 446 | if (next) { |
443 | *next = 0; | 447 | *next = '\0'; |
444 | next--; | 448 | next--; |
445 | } else | 449 | } else |
446 | next = end; | 450 | next = end; |
@@ -454,12 +458,11 @@ static struct dep_t *build_dep(void) | |||
454 | 458 | ||
455 | /* find the end of the module name in the file name */ | 459 | /* find the end of the module name in the file name */ |
456 | if (ENABLE_FEATURE_2_6_MODULES | 460 | if (ENABLE_FEATURE_2_6_MODULES |
457 | && (k_version > 4) && (*(next-2) == '.') | 461 | && (k_version > 4) && (next[-2] == '.') |
458 | && (*(next-1) == 'k') && (*next == 'o')) | 462 | && (next[-1] == 'k') && (next[0] == 'o')) |
459 | ext = 3; | 463 | ext = 3; |
460 | else | 464 | else if ((next[-1] == '.') && (next[0] == 'o')) |
461 | if ((*(next-1) == '.') && (*next == 'o')) | 465 | ext = 2; |
462 | ext = 2; | ||
463 | 466 | ||
464 | /* Cope with blank lines */ | 467 | /* Cope with blank lines */ |
465 | if ((next-deps-ext+1) <= 0) | 468 | if ((next-deps-ext+1) <= 0) |
@@ -477,11 +480,8 @@ static struct dep_t *build_dep(void) | |||
477 | } | 480 | } |
478 | 481 | ||
479 | /* is there other dependable module(s) ? */ | 482 | /* is there other dependable module(s) ? */ |
480 | if (buffer[l-1] == '\\') | 483 | continuation_line = (line_buffer[l-1] == '\\'); |
481 | continuation_line = 1; | 484 | } /* while (reads(...)) */ |
482 | else | ||
483 | continuation_line = 0; | ||
484 | } | ||
485 | close(fd); | 485 | close(fd); |
486 | 486 | ||
487 | /* | 487 | /* |
@@ -498,7 +498,7 @@ static struct dep_t *build_dep(void) | |||
498 | fd = open("/etc/conf.modules", O_RDONLY); | 498 | fd = open("/etc/conf.modules", O_RDONLY); |
499 | 499 | ||
500 | if (fd >= 0) { | 500 | if (fd >= 0) { |
501 | include_conf(&first, ¤t, buffer, sizeof(buffer), fd); | 501 | include_conf(&first, ¤t, line_buffer, sizeof(line_buffer), fd); |
502 | close(fd); | 502 | close(fd); |
503 | } | 503 | } |
504 | 504 | ||
@@ -515,7 +515,7 @@ static struct dep_t *build_dep(void) | |||
515 | free(filename); | 515 | free(filename); |
516 | 516 | ||
517 | if (fd >= 0) { | 517 | if (fd >= 0) { |
518 | include_conf(&first, ¤t, buffer, sizeof(buffer), fd); | 518 | include_conf(&first, ¤t, line_buffer, sizeof(line_buffer), fd); |
519 | close(fd); | 519 | close(fd); |
520 | } | 520 | } |
521 | 521 | ||
@@ -530,7 +530,7 @@ static struct dep_t *build_dep(void) | |||
530 | free(filename); | 530 | free(filename); |
531 | 531 | ||
532 | if (fd >= 0) { | 532 | if (fd >= 0) { |
533 | include_conf(&first, ¤t, buffer, sizeof(buffer), fd); | 533 | include_conf(&first, ¤t, line_buffer, sizeof(line_buffer), fd); |
534 | close(fd); | 534 | close(fd); |
535 | } | 535 | } |
536 | } | 536 | } |
@@ -542,16 +542,15 @@ static struct dep_t *build_dep(void) | |||
542 | static int already_loaded(const char *name) | 542 | static int already_loaded(const char *name) |
543 | { | 543 | { |
544 | int fd, ret = 0; | 544 | int fd, ret = 0; |
545 | char buffer[4096]; | ||
546 | 545 | ||
547 | fd = open("/proc/modules", O_RDONLY); | 546 | fd = open("/proc/modules", O_RDONLY); |
548 | if (fd < 0) | 547 | if (fd < 0) |
549 | return -1; | 548 | return -1; |
550 | 549 | ||
551 | while (reads(fd, buffer, sizeof(buffer))) { | 550 | while (reads(fd, line_buffer, sizeof(line_buffer))) { |
552 | char *p; | 551 | char *p; |
553 | 552 | ||
554 | p = strchr (buffer, ' '); | 553 | p = strchr(line_buffer, ' '); |
555 | if (p) { | 554 | if (p) { |
556 | const char *n; | 555 | const char *n; |
557 | 556 | ||
@@ -559,8 +558,8 @@ static int already_loaded(const char *name) | |||
559 | // the idiosyncrasy that _ and - are interchangeable because the | 558 | // the idiosyncrasy that _ and - are interchangeable because the |
560 | // 2.6 kernel does weird things. | 559 | // 2.6 kernel does weird things. |
561 | 560 | ||
562 | *p = 0; | 561 | *p = '\0'; |
563 | for (p = buffer, n = name; ; p++, n++) { | 562 | for (p = line_buffer, n = name; ; p++, n++) { |
564 | if (*p != *n) { | 563 | if (*p != *n) { |
565 | if ((*p == '_' || *p == '-') && (*n == '_' || *n == '-')) | 564 | if ((*p == '_' || *p == '-') && (*n == '_' || *n == '-')) |
566 | continue; | 565 | continue; |
@@ -574,8 +573,8 @@ static int already_loaded(const char *name) | |||
574 | } | 573 | } |
575 | } | 574 | } |
576 | } | 575 | } |
577 | done: | 576 | done: |
578 | close (fd); | 577 | close(fd); |
579 | return ret; | 578 | return ret; |
580 | } | 579 | } |
581 | 580 | ||
@@ -623,7 +622,7 @@ static int mod_process(const struct mod_list_t *list, int do_insert) | |||
623 | while (opts) { | 622 | while (opts) { |
624 | /* Add one more option */ | 623 | /* Add one more option */ |
625 | argc++; | 624 | argc++; |
626 | argv = xrealloc(argv,(argc + 1)* sizeof(char*)); | 625 | argv = xrealloc(argv, (argc + 1) * sizeof(char*)); |
627 | argv[argc-1] = opts->m_opt_val; | 626 | argv[argc-1] = opts->m_opt_val; |
628 | opts = opts->m_next; | 627 | opts = opts->m_next; |
629 | } | 628 | } |
@@ -698,9 +697,8 @@ static int check_pattern(const char* pat_src, const char* mod_src) | |||
698 | } | 697 | } |
699 | 698 | ||
700 | return ret; | 699 | return ret; |
701 | } else { | ||
702 | return fnmatch(pat_src, mod_src, 0); | ||
703 | } | 700 | } |
701 | return fnmatch(pat_src, mod_src, 0); | ||
704 | } | 702 | } |
705 | 703 | ||
706 | /* | 704 | /* |
@@ -712,8 +710,8 @@ static void check_dep(char *mod, struct mod_list_t **head, struct mod_list_t **t | |||
712 | { | 710 | { |
713 | struct mod_list_t *find; | 711 | struct mod_list_t *find; |
714 | struct dep_t *dt; | 712 | struct dep_t *dt; |
715 | struct mod_opt_t *opt = 0; | 713 | struct mod_opt_t *opt = NULL; |
716 | char *path = 0; | 714 | char *path = NULL; |
717 | 715 | ||
718 | /* Search for the given module name amongst all dependency rules. | 716 | /* Search for the given module name amongst all dependency rules. |
719 | * The module name in a dependency rule can be a shell pattern, | 717 | * The module name in a dependency rule can be a shell pattern, |
@@ -765,8 +763,8 @@ static void check_dep(char *mod, struct mod_list_t **head, struct mod_list_t **t | |||
765 | 763 | ||
766 | // search for duplicates | 764 | // search for duplicates |
767 | for (find = *head; find; find = find->m_next) { | 765 | for (find = *head; find; find = find->m_next) { |
768 | if (!strcmp(mod, find->m_name)) { | 766 | if (strcmp(mod, find->m_name) == 0) { |
769 | // found ->dequeue it | 767 | // found -> dequeue it |
770 | 768 | ||
771 | if (find->m_prev) | 769 | if (find->m_prev) |
772 | find->m_prev->m_next = find->m_next; | 770 | find->m_prev->m_next = find->m_next; |
@@ -783,7 +781,7 @@ static void check_dep(char *mod, struct mod_list_t **head, struct mod_list_t **t | |||
783 | } | 781 | } |
784 | 782 | ||
785 | if (!find) { // did not find a duplicate | 783 | if (!find) { // did not find a duplicate |
786 | find = xmalloc(sizeof(struct mod_list_t)); | 784 | find = xzalloc(sizeof(struct mod_list_t)); |
787 | find->m_name = mod; | 785 | find->m_name = mod; |
788 | find->m_path = path; | 786 | find->m_path = path; |
789 | find->m_options = opt; | 787 | find->m_options = opt; |
@@ -793,7 +791,7 @@ static void check_dep(char *mod, struct mod_list_t **head, struct mod_list_t **t | |||
793 | if (*tail) | 791 | if (*tail) |
794 | (*tail)->m_next = find; | 792 | (*tail)->m_next = find; |
795 | find->m_prev = *tail; | 793 | find->m_prev = *tail; |
796 | find->m_next = 0; | 794 | /*find->m_next = NULL; - xzalloc did it */ |
797 | 795 | ||
798 | if (!*head) | 796 | if (!*head) |
799 | *head = find; | 797 | *head = find; |
@@ -868,11 +866,11 @@ int modprobe_main(int argc, char **argv) | |||
868 | char *unused; | 866 | char *unused; |
869 | 867 | ||
870 | opt_complementary = "?V-:q-v:v-q"; | 868 | opt_complementary = "?V-:q-v:v-q"; |
871 | main_opts = getopt32(argv, "acdklnqrst:vVC:", | 869 | getopt32(argv, MAIN_OPT_STR, &unused, &unused); |
872 | &unused, &unused); | 870 | |
873 | if (main_opts & (DUMP_CONF_EXIT | LIST_ALL)) | 871 | if (option_mask32 & (DUMP_CONF_EXIT | LIST_ALL)) |
874 | return EXIT_SUCCESS; | 872 | return EXIT_SUCCESS; |
875 | if (main_opts & (RESTRICT_DIR | CONFIG_FILE)) | 873 | if (option_mask32 & (RESTRICT_DIR | CONFIG_FILE)) |
876 | bb_error_msg_and_die("-t and -C not supported"); | 874 | bb_error_msg_and_die("-t and -C not supported"); |
877 | 875 | ||
878 | depend = build_dep(); | 876 | depend = build_dep(); |
@@ -882,8 +880,8 @@ int modprobe_main(int argc, char **argv) | |||
882 | 880 | ||
883 | if (remove_opt) { | 881 | if (remove_opt) { |
884 | do { | 882 | do { |
885 | if (mod_remove(optind < argc ? | 883 | /* argv[optind] can be NULL here */ |
886 | argv[optind] : NULL)) { | 884 | if (mod_remove(argv[optind])) { |
887 | bb_error_msg("failed to remove module %s", | 885 | bb_error_msg("failed to remove module %s", |
888 | argv[optind]); | 886 | argv[optind]); |
889 | rc = EXIT_FAILURE; | 887 | rc = EXIT_FAILURE; |