aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griebl <griebl@gmx.de>2002-07-26 15:54:20 +0000
committerRobert Griebl <griebl@gmx.de>2002-07-26 15:54:20 +0000
commitaead70b4d15322d2eeee9384bacb2cc137f46f78 (patch)
tree3d36d61fc1faa1342f43b75a0be619d9bbcad94d
parentd0dd3d31e282b9aafaf499e4378cc2f691fea30a (diff)
downloadbusybox-w32-aead70b4d15322d2eeee9384bacb2cc137f46f78.tar.gz
busybox-w32-aead70b4d15322d2eeee9384bacb2cc137f46f78.tar.bz2
busybox-w32-aead70b4d15322d2eeee9384bacb2cc137f46f78.zip
modprobe now also uses "options" from /etc/modules.conf
-rw-r--r--modutils/modprobe.c154
1 files changed, 99 insertions, 55 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index b05158ac0..36d2aa211 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -1,9 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * really dumb modprobe implementation for busybox 3 * Modprobe written from scratch for BusyBox
4 * Copyright (C) 2001 Lineo, davidm@lineo.com
5 *
6 * dependency specific stuff completly rewritten and
7 * copyright (c) 2002 by Robert Griebl, griebl@gmx.de 4 * copyright (c) 2002 by Robert Griebl, griebl@gmx.de
8 * 5 *
9 */ 6 */
@@ -22,6 +19,7 @@
22 19
23struct dep_t { 20struct dep_t {
24 char * m_module; 21 char * m_module;
22 char * m_options;
25 23
26 int m_isalias : 1; 24 int m_isalias : 1;
27 int m_reserved : 15; 25 int m_reserved : 15;
@@ -34,6 +32,7 @@ struct dep_t {
34 32
35struct mod_list_t { 33struct mod_list_t {
36 char * m_module; 34 char * m_module;
35 char * m_options;
37 36
38 struct mod_list_t * m_prev; 37 struct mod_list_t * m_prev;
39 struct mod_list_t * m_next; 38 struct mod_list_t * m_next;
@@ -43,6 +42,24 @@ struct mod_list_t {
43static struct dep_t *depend; 42static struct dep_t *depend;
44static int autoclean, show_only, quiet, do_syslog, verbose; 43static int autoclean, show_only, quiet, do_syslog, verbose;
45 44
45int parse_tag_value ( char *buffer, char **ptag, char **pvalue )
46{
47 char *tag, *value;
48
49 while ( isspace ( *buffer ))
50 buffer++;
51 tag = value = buffer;
52 while ( !isspace ( *value ))
53 value++;
54 *value++ = 0;
55 while ( isspace ( *value ))
56 value++;
57
58 *ptag = tag;
59 *pvalue = value;
60
61 return xstrlen( tag ) && xstrlen( value );
62}
46 63
47/* Jump through hoops to simulate how fgets() grabs just one line at a 64/* Jump through hoops to simulate how fgets() grabs just one line at a
48 * time... Don't use any stdio since modprobe gets called from a kernel 65 * time... Don't use any stdio since modprobe gets called from a kernel
@@ -141,6 +158,7 @@ static struct dep_t *build_dep ( void )
141 current = current-> m_next; 158 current = current-> m_next;
142 } 159 }
143 current-> m_module = mod; 160 current-> m_module = mod;
161 current-> m_options = 0;
144 current-> m_isalias = 0; 162 current-> m_isalias = 0;
145 current-> m_depcnt = 0; 163 current-> m_depcnt = 0;
146 current-> m_deparr = 0; 164 current-> m_deparr = 0;
@@ -230,41 +248,49 @@ static struct dep_t *build_dep ( void )
230 if (( strncmp ( buffer, "alias", 5 ) == 0 ) && isspace ( buffer [5] )) { 248 if (( strncmp ( buffer, "alias", 5 ) == 0 ) && isspace ( buffer [5] )) {
231 char *alias, *mod; 249 char *alias, *mod;
232 250
233 alias = buffer + 6; 251 if ( parse_tag_value ( buffer + 6, &alias, &mod )) {
234 252 // fprintf ( stderr, "ALIAS: '%s' -> '%s'\n", alias, mod );
235 while ( isspace ( *alias ))
236 alias++;
237 mod = alias;
238 while ( !isspace ( *mod ))
239 mod++;
240 *mod = 0;
241 mod++;
242 while ( isspace ( *mod ))
243 mod++;
244
245// fprintf ( stderr, "ALIAS: '%s' -> '%s'\n", alias, mod );
246 253
247 if ( !current ) { 254 if ( !current ) {
248 first = current = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); 255 first = current = (struct dep_t *) xmalloc ( sizeof ( struct dep_t ));
249 } 256 }
250 else { 257 else {
251 current-> m_next = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); 258 current-> m_next = (struct dep_t *) xmalloc ( sizeof ( struct dep_t ));
252 current = current-> m_next; 259 current = current-> m_next;
260 }
261 current-> m_module = xstrdup ( alias );
262 current-> m_isalias = 1;
263
264 if (( strcmp ( alias, "off" ) == 0 ) || ( strcmp ( alias, "null" ) == 0 )) {
265 current-> m_depcnt = 0;
266 current-> m_deparr = 0;
267 }
268 else {
269 current-> m_depcnt = 1;
270 current-> m_deparr = xmalloc ( 1 * sizeof( char * ));
271 current-> m_deparr[0] = xstrdup ( mod );
272 }
273 current-> m_next = 0;
253 } 274 }
254 current-> m_module = xstrdup ( alias ); 275 }
255 current-> m_isalias = 1; 276 else if (( strncmp ( buffer, "options", 7 ) == 0 ) && isspace ( buffer [7] )) {
277 char *mod, *opt;
256 278
257 if (( strcmp ( alias, "off" ) == 0 ) || ( strcmp ( alias, "null" ) == 0 )) { 279 if ( parse_tag_value ( buffer + 8, &mod, &opt )) {
258 current-> m_depcnt = 0; 280 struct dep_t *dt;
259 current-> m_deparr = 0; 281
260 } 282 for ( dt = first; dt; dt = dt-> m_next ) {
261 else { 283 if ( strcmp ( dt-> m_module, mod ) == 0 )
262 current-> m_depcnt = 1; 284 break;
263 current-> m_deparr = xmalloc ( 1 * sizeof( char * )); 285 }
264 current-> m_deparr[0] = xstrdup ( mod ); 286 if ( dt ) {
287 dt-> m_options = xrealloc ( dt-> m_options, xstrlen( opt ) + 1 );
288 strcpy ( dt-> m_options, opt );
289
290 // fprintf ( stderr, "OPTION: '%s' -> '%s'\n", dt-> m_module, dt-> m_options );
291 }
265 } 292 }
266 current-> m_next = 0; 293 }
267 }
268 } 294 }
269 } 295 }
270 close ( fd ); 296 close ( fd );
@@ -283,7 +309,7 @@ static int mod_process ( struct mod_list_t *list, int do_insert )
283 309
284 while ( list ) { 310 while ( list ) {
285 if ( do_insert ) 311 if ( do_insert )
286 snprintf ( lcmd, sizeof( lcmd ) - 1, "insmod %s %s %s %s 2>/dev/null", do_syslog ? "-s" : "", autoclean ? "-k" : "", quiet ? "-q" : "", list-> m_module ); 312 snprintf ( lcmd, sizeof( lcmd ) - 1, "insmod %s %s %s %s %s 2>/dev/null", do_syslog ? "-s" : "", autoclean ? "-k" : "", quiet ? "-q" : "", list-> m_module, list-> m_options ? list-> m_options : "" );
287 else 313 else
288 snprintf ( lcmd, sizeof( lcmd ) - 1, "rmmod %s %s 2>/dev/null", do_syslog ? "-s" : "", list-> m_module ); 314 snprintf ( lcmd, sizeof( lcmd ) - 1, "rmmod %s %s 2>/dev/null", do_syslog ? "-s" : "", list-> m_module );
289 315
@@ -301,7 +327,7 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
301{ 327{
302 struct mod_list_t *find; 328 struct mod_list_t *find;
303 struct dep_t *dt; 329 struct dep_t *dt;
304 330 char *opt = 0;
305 int lm; 331 int lm;
306 332
307 // remove .o extension 333 // remove .o extension
@@ -311,16 +337,31 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
311 337
312 // check dependencies 338 // check dependencies
313 for ( dt = depend; dt; dt = dt-> m_next ) { 339 for ( dt = depend; dt; dt = dt-> m_next ) {
314 if ( strcmp ( dt-> m_module, mod ) == 0 ) 340 if ( strcmp ( dt-> m_module, mod ) == 0 ) {
341 opt = dt-> m_options;
315 break; 342 break;
343 }
316 } 344 }
345
317 // resolve alias names 346 // resolve alias names
318 if ( dt && dt-> m_isalias ) { 347 while ( dt && dt-> m_isalias ) {
319 if ( dt-> m_depcnt == 1 ) 348 if ( dt-> m_depcnt == 1 ) {
320 check_dep ( dt-> m_deparr [0], head, tail ); 349 struct dep_t *adt;
321 printf ( "Got alias: %s -> %s\n", mod, dt-> m_deparr [0] ); 350
322 351 for ( adt = depend; adt; adt = adt-> m_next ) {
323 return; 352 if ( strcmp ( adt-> m_module, dt-> m_deparr [0] ) == 0 ) {
353 if ( !opt )
354 opt = adt-> m_options;
355 break;
356 }
357 }
358 if ( !adt )
359 return;
360 else
361 dt = adt;
362 }
363 else
364 return;
324 } 365 }
325 366
326 // search for duplicates 367 // search for duplicates
@@ -345,6 +386,7 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
345 if ( !find ) { // did not find a duplicate 386 if ( !find ) { // did not find a duplicate
346 find = (struct mod_list_t *) xmalloc ( sizeof(struct mod_list_t)); 387 find = (struct mod_list_t *) xmalloc ( sizeof(struct mod_list_t));
347 find-> m_module = mod; 388 find-> m_module = mod;
389 find-> m_options = opt;
348 } 390 }
349 391
350 // enqueue at tail 392 // enqueue at tail
@@ -377,21 +419,23 @@ static int mod_insert ( char *mod, int argc, char **argv )
377 check_dep ( mod, &head, &tail ); 419 check_dep ( mod, &head, &tail );
378 420
379 if ( head && tail ) { 421 if ( head && tail ) {
380 int i; 422 if ( argc ) {
381 int l = 0; 423 int i;
424 int l = 0;
382 425
383 // append module args 426 // append module args
384 l = xstrlen ( head-> m_module ); 427 for ( i = 0; i < argc; i++ )
385 for ( i = 0; i < argc; i++ ) 428 l += ( xstrlen ( argv [i] ) + 1 );
386 l += ( xstrlen ( argv [i] ) + 1 );
387 429
388 head-> m_module = xrealloc ( head-> m_module, l + 1 ); 430 head-> m_options = xrealloc ( head-> m_options, l + 1 );
431 head-> m_options [0] = 0;
389 432
390 for ( i = 0; i < argc; i++ ) { 433 for ( i = 0; i < argc; i++ ) {
391 strcat ( head-> m_module, " " ); 434 strcat ( head-> m_options, argv [i] );
392 strcat ( head-> m_module, argv [i] ); 435 strcat ( head-> m_options, " " );
436 }
393 } 437 }
394 438
395 // process tail ---> head 439 // process tail ---> head
396 rc |= mod_process ( tail, 1 ); 440 rc |= mod_process ( tail, 1 );
397 } 441 }