diff options
| author | Robert Griebl <griebl@gmx.de> | 2002-05-28 21:32:10 +0000 |
|---|---|---|
| committer | Robert Griebl <griebl@gmx.de> | 2002-05-28 21:32:10 +0000 |
| commit | 1d4ef2a9e9c8d8b448bcce7dea36220e220e137b (patch) | |
| tree | 362aca2d9546fd51cc4d50f99db2f6cf542ba5e8 /modutils | |
| parent | 53146cc9ec7f3af5a8fa6245bf01c4f9c0fd19b4 (diff) | |
| download | busybox-w32-1d4ef2a9e9c8d8b448bcce7dea36220e220e137b.tar.gz busybox-w32-1d4ef2a9e9c8d8b448bcce7dea36220e220e137b.tar.bz2 busybox-w32-1d4ef2a9e9c8d8b448bcce7dea36220e220e137b.zip | |
Added support for /etc/modules.conf parsing
for now only the 'alias' entries are evaluated
Diffstat (limited to 'modutils')
| -rw-r--r-- | modutils/modprobe.c | 123 |
1 files changed, 105 insertions, 18 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 9230fec85..a510f69e8 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
| @@ -23,7 +23,10 @@ | |||
| 23 | struct dep_t { | 23 | struct dep_t { |
| 24 | char * m_module; | 24 | char * m_module; |
| 25 | 25 | ||
| 26 | int m_depcnt; | 26 | int m_isalias : 1; |
| 27 | int m_reserved : 15; | ||
| 28 | |||
| 29 | int m_depcnt : 16; | ||
| 27 | char ** m_deparr; | 30 | char ** m_deparr; |
| 28 | 31 | ||
| 29 | struct dep_t * m_next; | 32 | struct dep_t * m_next; |
| @@ -70,7 +73,7 @@ static struct dep_t *build_dep ( void ) | |||
| 70 | int l = xstrlen ( buffer ); | 73 | int l = xstrlen ( buffer ); |
| 71 | char *p = 0; | 74 | char *p = 0; |
| 72 | 75 | ||
| 73 | if ( buffer [l-1] == '\n' ) { | 76 | while ( isspace ( buffer [l-1] )) { |
| 74 | buffer [l-1] = 0; | 77 | buffer [l-1] = 0; |
| 75 | l--; | 78 | l--; |
| 76 | } | 79 | } |
| @@ -108,10 +111,11 @@ static struct dep_t *build_dep ( void ) | |||
| 108 | current-> m_next = (struct dep_t *) malloc ( sizeof ( struct dep_t )); | 111 | current-> m_next = (struct dep_t *) malloc ( sizeof ( struct dep_t )); |
| 109 | current = current-> m_next; | 112 | current = current-> m_next; |
| 110 | } | 113 | } |
| 111 | current-> m_module = mod; | 114 | current-> m_module = mod; |
| 112 | current-> m_depcnt = 0; | 115 | current-> m_isalias = 0; |
| 113 | current-> m_deparr = 0; | 116 | current-> m_depcnt = 0; |
| 114 | current-> m_next = 0; | 117 | current-> m_deparr = 0; |
| 118 | current-> m_next = 0; | ||
| 115 | 119 | ||
| 116 | //printf ( "%s:\n", mod ); | 120 | //printf ( "%s:\n", mod ); |
| 117 | 121 | ||
| @@ -161,6 +165,78 @@ static struct dep_t *build_dep ( void ) | |||
| 161 | continuation_line = 0; | 165 | continuation_line = 0; |
| 162 | } | 166 | } |
| 163 | fclose ( f ); | 167 | fclose ( f ); |
| 168 | |||
| 169 | // alias parsing is not 100% correct (no correct handling of continuation lines within an alias) ! | ||
| 170 | |||
| 171 | f = fopen ( "/etc/modules.conf", "r" ); | ||
| 172 | if ( !f ) | ||
| 173 | f = fopen ( "/etc/conf.modules", "r" ); | ||
| 174 | if ( f ) { | ||
| 175 | continuation_line = 0; | ||
| 176 | |||
| 177 | while ( fgets ( buffer, sizeof( buffer), f )) { | ||
| 178 | int l; | ||
| 179 | char *p; | ||
| 180 | |||
| 181 | p = strchr ( buffer, '#' ); | ||
| 182 | if ( p ) | ||
| 183 | *p = 0; | ||
| 184 | |||
| 185 | l = xstrlen ( buffer ); | ||
| 186 | |||
| 187 | while ( l && isspace ( buffer [l-1] )) { | ||
| 188 | buffer [l-1] = 0; | ||
| 189 | l--; | ||
| 190 | } | ||
| 191 | |||
| 192 | if ( l == 0 ) { | ||
| 193 | continuation_line = 0; | ||
| 194 | continue; | ||
| 195 | } | ||
| 196 | |||
| 197 | if ( !continuation_line ) { | ||
| 198 | if (( strncmp ( buffer, "alias", 5 ) == 0 ) && isspace ( buffer [5] )) { | ||
| 199 | char *alias, *mod; | ||
| 200 | |||
| 201 | alias = buffer + 6; | ||
| 202 | |||
| 203 | while ( isspace ( *alias )) | ||
| 204 | alias++; | ||
| 205 | mod = alias; | ||
| 206 | while ( !isspace ( *mod )) | ||
| 207 | mod++; | ||
| 208 | *mod = 0; | ||
| 209 | mod++; | ||
| 210 | while ( isspace ( *mod )) | ||
| 211 | mod++; | ||
| 212 | |||
| 213 | // fprintf ( stderr, "ALIAS: '%s' -> '%s'\n", alias, mod ); | ||
| 214 | |||
| 215 | if ( !current ) { | ||
| 216 | first = current = (struct dep_t *) malloc ( sizeof ( struct dep_t )); | ||
| 217 | } | ||
| 218 | else { | ||
| 219 | current-> m_next = (struct dep_t *) malloc ( sizeof ( struct dep_t )); | ||
| 220 | current = current-> m_next; | ||
| 221 | } | ||
| 222 | current-> m_module = xstrdup ( alias ); | ||
| 223 | current-> m_isalias = 1; | ||
| 224 | |||
| 225 | if (( strcmp ( alias, "off" ) == 0 ) || ( strcmp ( alias, "null" ) == 0 )) { | ||
| 226 | current-> m_depcnt = 0; | ||
| 227 | current-> m_deparr = 0; | ||
| 228 | } | ||
| 229 | else { | ||
| 230 | current-> m_depcnt = 1; | ||
| 231 | current-> m_deparr = xmalloc ( 1 * sizeof( char * )); | ||
| 232 | current-> m_deparr[0] = xstrdup ( mod ); | ||
| 233 | } | ||
| 234 | current-> m_next = 0; | ||
| 235 | } | ||
| 236 | } | ||
| 237 | } | ||
| 238 | fclose ( f ); | ||
| 239 | } | ||
| 164 | 240 | ||
| 165 | return first; | 241 | return first; |
| 166 | } | 242 | } |
| @@ -202,6 +278,20 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t * | |||
| 202 | if (( mod [lm-2] == '.' ) && ( mod [lm-1] == 'o' )) | 278 | if (( mod [lm-2] == '.' ) && ( mod [lm-1] == 'o' )) |
| 203 | mod [lm-2] = 0; | 279 | mod [lm-2] = 0; |
| 204 | 280 | ||
| 281 | // check dependencies | ||
| 282 | for ( dt = depend; dt; dt = dt-> m_next ) { | ||
| 283 | if ( strcmp ( dt-> m_module, mod ) == 0 ) | ||
| 284 | break; | ||
| 285 | } | ||
| 286 | // resolve alias names | ||
| 287 | if ( dt && dt-> m_isalias ) { | ||
| 288 | if ( dt-> m_depcnt == 1 ) | ||
| 289 | check_dep ( dt-> m_deparr [0], head, tail ); | ||
| 290 | printf ( "Got alias: %s -> %s\n", mod, dt-> m_deparr [0] ); | ||
| 291 | |||
| 292 | return; | ||
| 293 | } | ||
| 294 | |||
| 205 | // search for duplicates | 295 | // search for duplicates |
| 206 | for ( find = *head; find; find = find-> m_next ) { | 296 | for ( find = *head; find; find = find-> m_next ) { |
| 207 | if ( !strcmp ( mod, find-> m_module )) { | 297 | if ( !strcmp ( mod, find-> m_module )) { |
| @@ -231,20 +321,17 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t * | |||
| 231 | (*tail)-> m_next = find; | 321 | (*tail)-> m_next = find; |
| 232 | find-> m_prev = *tail; | 322 | find-> m_prev = *tail; |
| 233 | find-> m_next = 0; | 323 | find-> m_next = 0; |
| 234 | 324 | ||
| 235 | if ( !*head ) | 325 | if ( !*head ) |
| 236 | *head = find; | 326 | *head = find; |
| 237 | *tail = find; | 327 | *tail = find; |
| 238 | 328 | ||
| 239 | // check dependencies | 329 | if ( dt ) { |
| 240 | for ( dt = depend; dt; dt = dt-> m_next ) { | 330 | int i; |
| 241 | if ( !strcmp ( dt-> m_module, mod )) { | 331 | |
| 242 | int i; | 332 | for ( i = 0; i < dt-> m_depcnt; i++ ) |
| 243 | 333 | check_dep ( dt-> m_deparr [i], head, tail ); | |
| 244 | for ( i = 0; i < dt-> m_depcnt; i++ ) | 334 | } |
| 245 | check_dep ( dt-> m_deparr [i], head, tail ); | ||
| 246 | } | ||
| 247 | } | ||
| 248 | } | 335 | } |
| 249 | 336 | ||
| 250 | 337 | ||
| @@ -263,11 +350,11 @@ static int mod_insert ( char *mod, int argc, char **argv ) | |||
| 263 | int l = 0; | 350 | int l = 0; |
| 264 | 351 | ||
| 265 | // append module args | 352 | // append module args |
| 266 | l = xstrlen ( mod ); | 353 | l = xstrlen ( head-> m_module ); |
| 267 | for ( i = 0; i < argc; i++ ) | 354 | for ( i = 0; i < argc; i++ ) |
| 268 | l += ( xstrlen ( argv [i] ) + 1 ); | 355 | l += ( xstrlen ( argv [i] ) + 1 ); |
| 269 | 356 | ||
| 270 | head-> m_module = xstrndup ( mod, l ); | 357 | head-> m_module = realloc ( head-> m_module, l + 1 ); |
| 271 | 358 | ||
| 272 | for ( i = 0; i < argc; i++ ) { | 359 | for ( i = 0; i < argc; i++ ) { |
| 273 | strcat ( head-> m_module, " " ); | 360 | strcat ( head-> m_module, " " ); |
