diff options
author | Rob Landley <rob@landley.net> | 2006-04-10 16:09:52 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-04-10 16:09:52 +0000 |
commit | 72615752db145128bd494a0d54eaa56fa8936e49 (patch) | |
tree | 22f90c6939e3d837066267b2c39163b40e5542f4 | |
parent | 6554de06fe4f218546fc2b1e2f6c5a41995e2353 (diff) | |
download | busybox-w32-72615752db145128bd494a0d54eaa56fa8936e49.tar.gz busybox-w32-72615752db145128bd494a0d54eaa56fa8936e49.tar.bz2 busybox-w32-72615752db145128bd494a0d54eaa56fa8936e49.zip |
Modprobe update from Ignacio García Pérez, updating support for modprobe.conf.
-rw-r--r-- | modutils/modprobe.c | 182 |
1 files changed, 109 insertions, 73 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 8defd2854..32a37ce17 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
@@ -266,6 +266,104 @@ static char *parse_command_string( char *src, char **dst ) | |||
266 | #endif /* ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS */ | 266 | #endif /* ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS */ |
267 | 267 | ||
268 | /* | 268 | /* |
269 | * This function reads aliases and default module options from a configuration file | ||
270 | * (/etc/modprobe.conf syntax). It supports includes (only files, no directories). | ||
271 | */ | ||
272 | static void include_conf ( struct dep_t **first, struct dep_t **current, char *buffer, int buflen, int fd ) | ||
273 | { | ||
274 | int continuation_line = 0; | ||
275 | |||
276 | // alias parsing is not 100% correct (no correct handling of continuation lines within an alias) ! | ||
277 | |||
278 | while ( reads ( fd, buffer, buflen)) { | ||
279 | int l; | ||
280 | char *p; | ||
281 | |||
282 | p = strchr ( buffer, '#' ); | ||
283 | if ( p ) | ||
284 | *p = 0; | ||
285 | |||
286 | l = bb_strlen ( buffer ); | ||
287 | |||
288 | while ( l && isspace ( buffer [l-1] )) { | ||
289 | buffer [l-1] = 0; | ||
290 | l--; | ||
291 | } | ||
292 | |||
293 | if ( l == 0 ) { | ||
294 | continuation_line = 0; | ||
295 | continue; | ||
296 | } | ||
297 | |||
298 | if ( !continuation_line ) { | ||
299 | if (( strncmp ( buffer, "alias", 5 ) == 0 ) && isspace ( buffer [5] )) { | ||
300 | char *alias, *mod; | ||
301 | |||
302 | if ( parse_tag_value ( buffer + 6, &alias, &mod )) { | ||
303 | /* handle alias as a module dependent on the aliased module */ | ||
304 | if ( !*current ) { | ||
305 | (*first) = (*current) = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t )); | ||
306 | } | ||
307 | else { | ||
308 | (*current)-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t )); | ||
309 | (*current) = (*current)-> m_next; | ||
310 | } | ||
311 | (*current)-> m_name = bb_xstrdup ( alias ); | ||
312 | (*current)-> m_isalias = 1; | ||
313 | |||
314 | if (( strcmp ( mod, "off" ) == 0 ) || ( strcmp ( mod, "null" ) == 0 )) { | ||
315 | (*current)-> m_depcnt = 0; | ||
316 | (*current)-> m_deparr = 0; | ||
317 | } | ||
318 | else { | ||
319 | (*current)-> m_depcnt = 1; | ||
320 | (*current)-> m_deparr = xmalloc ( 1 * sizeof( char * )); | ||
321 | (*current)-> m_deparr[0] = bb_xstrdup ( mod ); | ||
322 | } | ||
323 | (*current)-> m_next = 0; | ||
324 | } | ||
325 | } | ||
326 | else if (( strncmp ( buffer, "options", 7 ) == 0 ) && isspace ( buffer [7] )) { | ||
327 | char *mod, *opt; | ||
328 | |||
329 | /* split the line in the module/alias name, and options */ | ||
330 | if ( parse_tag_value ( buffer + 8, &mod, &opt )) { | ||
331 | struct dep_t *dt; | ||
332 | |||
333 | /* find the corresponding module */ | ||
334 | for ( dt = *first; dt; dt = dt-> m_next ) { | ||
335 | if ( strcmp ( dt-> m_name, mod ) == 0 ) | ||
336 | break; | ||
337 | } | ||
338 | if ( dt ) { | ||
339 | if ( ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS ) { | ||
340 | char* new_opt = NULL; | ||
341 | while( ( opt = parse_command_string( opt, &new_opt ) ) ) { | ||
342 | dt-> m_options = append_option( dt-> m_options, new_opt ); | ||
343 | } | ||
344 | } else { | ||
345 | dt-> m_options = append_option( dt-> m_options, opt ); | ||
346 | } | ||
347 | } | ||
348 | } | ||
349 | } | ||
350 | else if (( strncmp ( buffer, "include", 7 ) == 0 ) && isspace ( buffer [7] )) { | ||
351 | |||
352 | int fdi; char *filename = buffer + 8; | ||
353 | |||
354 | while ( isspace ( *filename )) | ||
355 | filename++; | ||
356 | |||
357 | if (( fdi = open ( filename, O_RDONLY )) >= 0 ) { | ||
358 | include_conf(first, current, buffer, buflen, fdi); | ||
359 | close(fdi); | ||
360 | } | ||
361 | } | ||
362 | } | ||
363 | } | ||
364 | } | ||
365 | |||
366 | /* | ||
269 | * This function builds a list of dependency rules from /lib/modules/`uname -r\modules.dep. | 367 | * This function builds a list of dependency rules from /lib/modules/`uname -r\modules.dep. |
270 | * It then fills every modules and aliases with their default options, found by parsing | 368 | * It then fills every modules and aliases with their default options, found by parsing |
271 | * modprobe.conf (or modules.conf, or conf.modules). | 369 | * modprobe.conf (or modules.conf, or conf.modules). |
@@ -446,90 +544,28 @@ static struct dep_t *build_dep ( void ) | |||
446 | } | 544 | } |
447 | close ( fd ); | 545 | close ( fd ); |
448 | 546 | ||
449 | // alias parsing is not 100% correct (no correct handling of continuation lines within an alias) ! | ||
450 | |||
451 | if (!ENABLE_FEATURE_2_6_MODULES | 547 | if (!ENABLE_FEATURE_2_6_MODULES |
452 | || ( fd = open ( "/etc/modprobe.conf", O_RDONLY )) < 0 ) | 548 | || ( fd = open ( "/etc/modprobe.conf", O_RDONLY )) < 0 ) |
453 | if (( fd = open ( "/etc/modules.conf", O_RDONLY )) < 0 ) | 549 | if (( fd = open ( "/etc/modules.conf", O_RDONLY )) < 0 ) |
454 | if (( fd = open ( "/etc/conf.modules", O_RDONLY )) < 0 ) | 550 | if (( fd = open ( "/etc/conf.modules", O_RDONLY )) < 0 ) |
455 | return first; | 551 | return first; |
456 | 552 | ||
457 | continuation_line = 0; | 553 | include_conf (&first, ¤t, buffer, sizeof(buffer), fd); |
458 | while ( reads ( fd, buffer, sizeof( buffer ))) { | 554 | close(fd); |
459 | int l; | ||
460 | char *p; | ||
461 | |||
462 | p = strchr ( buffer, '#' ); | ||
463 | if ( p ) | ||
464 | *p = 0; | ||
465 | |||
466 | l = bb_strlen ( buffer ); | ||
467 | |||
468 | while ( l && isspace ( buffer [l-1] )) { | ||
469 | buffer [l-1] = 0; | ||
470 | l--; | ||
471 | } | ||
472 | |||
473 | if ( l == 0 ) { | ||
474 | continuation_line = 0; | ||
475 | continue; | ||
476 | } | ||
477 | |||
478 | if ( !continuation_line ) { | ||
479 | if (( strncmp ( buffer, "alias", 5 ) == 0 ) && isspace ( buffer [5] )) { | ||
480 | char *alias, *mod; | ||
481 | |||
482 | if ( parse_tag_value ( buffer + 6, &alias, &mod )) { | ||
483 | /* handle alias as a module dependent on the aliased module */ | ||
484 | if ( !current ) { | ||
485 | first = current = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t )); | ||
486 | } | ||
487 | else { | ||
488 | current-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t )); | ||
489 | current = current-> m_next; | ||
490 | } | ||
491 | current-> m_name = bb_xstrdup ( alias ); | ||
492 | current-> m_isalias = 1; | ||
493 | 555 | ||
494 | if (( strcmp ( mod, "off" ) == 0 ) || ( strcmp ( mod, "null" ) == 0 )) { | 556 | filename = bb_xasprintf("/lib/modules/%s/modules.alias", un.release ); |
495 | current-> m_depcnt = 0; | ||
496 | current-> m_deparr = 0; | ||
497 | } | ||
498 | else { | ||
499 | current-> m_depcnt = 1; | ||
500 | current-> m_deparr = xmalloc ( 1 * sizeof( char * )); | ||
501 | current-> m_deparr[0] = bb_xstrdup ( mod ); | ||
502 | } | ||
503 | current-> m_next = 0; | ||
504 | } | ||
505 | } | ||
506 | else if (( strncmp ( buffer, "options", 7 ) == 0 ) && isspace ( buffer [7] )) { | ||
507 | char *mod, *opt; | ||
508 | 557 | ||
509 | /* split the line in the module/alias name, and options */ | 558 | if (( fd = open ( filename, O_RDONLY )) < 0 ) { |
510 | if ( parse_tag_value ( buffer + 8, &mod, &opt )) { | ||
511 | struct dep_t *dt; | ||
512 | 559 | ||
513 | /* find the corresponding module */ | 560 | /* Ok, that didn't work. Fall back to looking in /lib/modules */ |
514 | for ( dt = first; dt; dt = dt-> m_next ) { | 561 | if (( fd = open ( "/lib/modules/modules.alias", O_RDONLY )) < 0 ) { |
515 | if ( strcmp ( dt-> m_name, mod ) == 0 ) | 562 | return first; |
516 | break; | ||
517 | } | ||
518 | if ( dt ) { | ||
519 | if ( ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS ) { | ||
520 | char* new_opt = NULL; | ||
521 | while( ( opt = parse_command_string( opt, &new_opt ) ) ) { | ||
522 | dt-> m_options = append_option( dt-> m_options, new_opt ); | ||
523 | } | ||
524 | } else { | ||
525 | dt-> m_options = append_option( dt-> m_options, opt ); | ||
526 | } | ||
527 | } | ||
528 | } | ||
529 | } | ||
530 | } | 563 | } |
531 | } | 564 | } |
532 | close ( fd ); | 565 | free(filename); |
566 | |||
567 | include_conf (&first, ¤t, buffer, sizeof(buffer), fd); | ||
568 | close(fd); | ||
533 | 569 | ||
534 | return first; | 570 | return first; |
535 | } | 571 | } |