summaryrefslogtreecommitdiff
path: root/modutils/modprobe.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-08-19 18:30:31 +0000
committerEric Andersen <andersen@codepoet.org>2004-08-19 18:30:31 +0000
commit807bd846b6428920eb2f10875f19a7e48d8cfdd7 (patch)
tree39aaded2e373a66a903e754efb4f04fd3310c8ea /modutils/modprobe.c
parenta4fcccefa6fda72c0b73f4ef9f391dd5f1f74602 (diff)
downloadbusybox-w32-807bd846b6428920eb2f10875f19a7e48d8cfdd7.tar.gz
busybox-w32-807bd846b6428920eb2f10875f19a7e48d8cfdd7.tar.bz2
busybox-w32-807bd846b6428920eb2f10875f19a7e48d8cfdd7.zip
Patch from Mike Castle to cleanup some modutils issues, in
particular making alias support work better.
Diffstat (limited to 'modutils/modprobe.c')
-rw-r--r--modutils/modprobe.c92
1 files changed, 33 insertions, 59 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index 7d6115380..98003ca16 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -34,7 +34,8 @@
34 34
35 35
36struct dep_t { 36struct dep_t {
37 char * m_module; 37 char * m_name;
38 char * m_path;
38 char * m_options; 39 char * m_options;
39 40
40 int m_isalias : 1; 41 int m_isalias : 1;
@@ -47,7 +48,8 @@ struct dep_t {
47}; 48};
48 49
49struct mod_list_t { 50struct mod_list_t {
50 char * m_module; 51 char * m_name;
52 char * m_path;
51 char * m_options; 53 char * m_options;
52 54
53 struct mod_list_t * m_prev; 55 struct mod_list_t * m_prev;
@@ -159,11 +161,12 @@ static struct dep_t *build_dep ( void )
159 161
160 if ( !continuation_line ) { 162 if ( !continuation_line ) {
161 char *col = strchr ( buffer, ':' ); 163 char *col = strchr ( buffer, ':' );
164 char *dot = col;
162 165
163 if ( col ) { 166 if ( col ) {
164 char *mods; 167 char *mods;
168 char *modpath;
165 char *mod; 169 char *mod;
166 int ext = 0;
167 170
168 *col = 0; 171 *col = 0;
169 mods = strrchr ( buffer, '/' ); 172 mods = strrchr ( buffer, '/' );
@@ -173,16 +176,19 @@ static struct dep_t *build_dep ( void )
173 else 176 else
174 mods++; 177 mods++;
175 178
179 modpath = strchr ( buffer, '/' );
180 if ( !modpath )
181 modpath = buffer;
176#if defined(CONFIG_FEATURE_2_6_MODULES) 182#if defined(CONFIG_FEATURE_2_6_MODULES)
177 if ((k_version > 4) && ( *(col-3) == '.' ) && 183 if ((k_version > 4) && ( *(col-3) == '.' ) &&
178 ( *(col-2) == 'k' ) && ( *(col-1) == 'o' )) 184 ( *(col-2) == 'k' ) && ( *(col-1) == 'o' ))
179 ext = 3; 185 dot = col - 3;
180 else 186 else
181#endif 187#endif
182 if (( *(col-2) == '.' ) && ( *(col-1) == 'o' )) 188 if (( *(col-2) == '.' ) && ( *(col-1) == 'o' ))
183 ext = 2; 189 dot = col - 2;
184 190
185 mod = bb_xstrndup ( buffer, col - buffer ); 191 mod = bb_xstrndup ( mods, dot - mods );
186 192
187 if ( !current ) { 193 if ( !current ) {
188 first = current = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); 194 first = current = (struct dep_t *) xmalloc ( sizeof ( struct dep_t ));
@@ -191,7 +197,8 @@ static struct dep_t *build_dep ( void )
191 current-> m_next = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); 197 current-> m_next = (struct dep_t *) xmalloc ( sizeof ( struct dep_t ));
192 current = current-> m_next; 198 current = current-> m_next;
193 } 199 }
194 current-> m_module = mod; 200 current-> m_name = mod;
201 current-> m_path = bb_xstrdup(modpath);
195 current-> m_options = 0; 202 current-> m_options = 0;
196 current-> m_isalias = 0; 203 current-> m_isalias = 0;
197 current-> m_depcnt = 0; 204 current-> m_depcnt = 0;
@@ -317,7 +324,7 @@ static struct dep_t *build_dep ( void )
317 current-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t )); 324 current-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t ));
318 current = current-> m_next; 325 current = current-> m_next;
319 } 326 }
320 current-> m_module = bb_xstrdup ( alias ); 327 current-> m_name = bb_xstrdup ( alias );
321 current-> m_isalias = 1; 328 current-> m_isalias = 1;
322 329
323 if (( strcmp ( mod, "off" ) == 0 ) || ( strcmp ( mod, "null" ) == 0 )) { 330 if (( strcmp ( mod, "off" ) == 0 ) || ( strcmp ( mod, "null" ) == 0 )) {
@@ -339,14 +346,14 @@ static struct dep_t *build_dep ( void )
339 struct dep_t *dt; 346 struct dep_t *dt;
340 347
341 for ( dt = first; dt; dt = dt-> m_next ) { 348 for ( dt = first; dt; dt = dt-> m_next ) {
342 if ( strcmp ( dt-> m_module, mod ) == 0 ) 349 if ( strcmp ( dt-> m_name, mod ) == 0 )
343 break; 350 break;
344 } 351 }
345 if ( dt ) { 352 if ( dt ) {
346 dt-> m_options = xrealloc ( dt-> m_options, bb_strlen( opt ) + 1 ); 353 dt-> m_options = xrealloc ( dt-> m_options, bb_strlen( opt ) + 1 );
347 strcpy ( dt-> m_options, opt ); 354 strcpy ( dt-> m_options, opt );
348 355
349 // fprintf ( stderr, "OPTION: '%s' -> '%s'\n", dt-> m_module, dt-> m_options ); 356 // fprintf ( stderr, "OPTION: '%s' -> '%s'\n", dt-> m_name, dt-> m_options );
350 } 357 }
351 } 358 }
352 } 359 }
@@ -357,29 +364,6 @@ static struct dep_t *build_dep ( void )
357 return first; 364 return first;
358} 365}
359 366
360/* check if /lib/modules/bar/foo.ko belongs to module foo */
361/* return 1 = found, 0 = not found */
362static int mod_strcmp ( const char *mod_path, const char *mod_name )
363{
364 /* last path component */
365 const char *last_comp = strrchr (mod_path, '/');
366 const char *mod_ext = ".o";
367
368#if defined(CONFIG_FEATURE_2_6_MODULES)
369 if ( k_version > 4 )
370 mod_ext = ".ko";
371#endif
372
373 last_comp = last_comp ? last_comp + 1 : mod_path;
374
375 return (strncmp(last_comp,
376 mod_name,
377 strlen(mod_name)) == 0 ) &&
378 ((strcmp(last_comp + strlen (mod_name), mod_ext) == 0) || last_comp[strlen(mod_name)] == 0) &&
379 (strcmp(mod_path + strlen(mod_path) -
380 strlen(mod_ext), mod_ext) == 0);
381}
382
383/* return 1 = loaded, 0 = not loaded, -1 = can't tell */ 367/* return 1 = loaded, 0 = not loaded, -1 = can't tell */
384static int already_loaded (const char *name) 368static int already_loaded (const char *name)
385{ 369{
@@ -396,7 +380,7 @@ static int already_loaded (const char *name)
396 p = strchr (buffer, ' '); 380 p = strchr (buffer, ' ');
397 if (p) { 381 if (p) {
398 *p = 0; 382 *p = 0;
399 if (mod_strcmp (name, buffer)) { 383 if (strcmp (name, buffer) == 0) {
400 close (fd); 384 close (fd);
401 return 1; 385 return 1;
402 } 386 }
@@ -415,15 +399,16 @@ static int mod_process ( struct mod_list_t *list, int do_insert )
415 while ( list ) { 399 while ( list ) {
416 *lcmd = '\0'; 400 *lcmd = '\0';
417 if ( do_insert ) { 401 if ( do_insert ) {
418 if (already_loaded (list->m_module) != 1) 402 if (already_loaded (list->m_name) != 1)
419 snprintf ( lcmd, sizeof( lcmd ) - 1, "insmod %s %s %s %s %s", 403 snprintf ( lcmd, sizeof( lcmd ) - 1, "insmod %s %s %s %s %s",
420 do_syslog ? "-s" : "", autoclean ? "-k" : "", 404 do_syslog ? "-s" : "", autoclean ? "-k" : "",
421 quiet ? "-q" : "", list-> m_module, list-> m_options ? 405 quiet ? "-q" : "", list-> m_path, list-> m_options ?
422 list-> m_options : "" ); 406 list-> m_options : "" );
423 } else { 407 } else {
424 if (already_loaded (list->m_module) != 0) 408 /* modutils uses short name for removal */
409 if (already_loaded (list->m_name) != 0)
425 snprintf ( lcmd, sizeof( lcmd ) - 1, "rmmod %s %s", 410 snprintf ( lcmd, sizeof( lcmd ) - 1, "rmmod %s %s",
426 do_syslog ? "-s" : "", list-> m_module ); 411 do_syslog ? "-s" : "", list-> m_name );
427 } 412 }
428 413
429 if (*lcmd) { 414 if (*lcmd) {
@@ -450,24 +435,13 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
450 struct mod_list_t *find; 435 struct mod_list_t *find;
451 struct dep_t *dt; 436 struct dep_t *dt;
452 char *opt = 0; 437 char *opt = 0;
453 int lm; 438 char *path = 0;
454
455 // remove .o extension
456 lm = bb_strlen ( mod );
457
458#if defined(CONFIG_FEATURE_2_6_MODULES)
459 if ((k_version > 4) && ( mod [lm-3] == '.' ) &&
460 ( mod [lm-2] == 'k' ) && ( mod [lm-1] == 'o' ))
461 mod [lm-3] = 0;
462 else
463#endif
464 if (( mod [lm-2] == '.' ) && ( mod [lm-1] == 'o' ))
465 mod [lm-2] = 0;
466 439
467 // check dependencies 440 // check dependencies
468 for ( dt = depend; dt; dt = dt-> m_next ) { 441 for ( dt = depend; dt; dt = dt-> m_next ) {
469 if ( mod_strcmp ( dt-> m_module, mod )) { 442 if ( strcmp ( dt-> m_name, mod ) == 0) {
470 mod = dt-> m_module; 443 mod = dt-> m_name;
444 path = dt-> m_path;
471 opt = dt-> m_options; 445 opt = dt-> m_options;
472 break; 446 break;
473 } 447 }
@@ -479,12 +453,13 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
479 struct dep_t *adt; 453 struct dep_t *adt;
480 454
481 for ( adt = depend; adt; adt = adt-> m_next ) { 455 for ( adt = depend; adt; adt = adt-> m_next ) {
482 if ( strcmp ( adt-> m_module, dt-> m_deparr [0] ) == 0 ) 456 if ( strcmp ( adt-> m_name, dt-> m_deparr [0] ) == 0 )
483 break; 457 break;
484 } 458 }
485 if ( adt ) { 459 if ( adt ) {
486 dt = adt; 460 dt = adt;
487 mod = dt-> m_module; 461 mod = dt-> m_name;
462 path = dt-> m_path;
488 if ( !opt ) 463 if ( !opt )
489 opt = dt-> m_options; 464 opt = dt-> m_options;
490 } 465 }
@@ -497,7 +472,7 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
497 472
498 // search for duplicates 473 // search for duplicates
499 for ( find = *head; find; find = find-> m_next ) { 474 for ( find = *head; find; find = find-> m_next ) {
500 if ( !strcmp ( mod, find-> m_module )) { 475 if ( !strcmp ( mod, find-> m_name )) {
501 // found -> dequeue it 476 // found -> dequeue it
502 477
503 if ( find-> m_prev ) 478 if ( find-> m_prev )
@@ -516,7 +491,8 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
516 491
517 if ( !find ) { // did not find a duplicate 492 if ( !find ) { // did not find a duplicate
518 find = (struct mod_list_t *) xmalloc ( sizeof(struct mod_list_t)); 493 find = (struct mod_list_t *) xmalloc ( sizeof(struct mod_list_t));
519 find-> m_module = mod; 494 find-> m_name = mod;
495 find-> m_path = path;
520 find-> m_options = opt; 496 find-> m_options = opt;
521 } 497 }
522 498
@@ -599,8 +575,6 @@ static int mod_remove ( char *mod )
599 575
600} 576}
601 577
602
603
604extern int modprobe_main(int argc, char** argv) 578extern int modprobe_main(int argc, char** argv)
605{ 579{
606 int opt; 580 int opt;