summaryrefslogtreecommitdiff
path: root/modutils/modprobe.c
diff options
context:
space:
mode:
authorEric Andersen2003-12-24 20:30:45 +0000
committerEric Andersen2003-12-24 20:30:45 +0000
commit3b1a74467a0909a62f26f6f27ac63ea922939c4d (patch)
tree982459b4484a823360ec90628a18d72e26902fbf /modutils/modprobe.c
parentd242e49c894cd0a8b6b016e8f1865651c1c5fef7 (diff)
downloadbusybox-3b1a74467a0909a62f26f6f27ac63ea922939c4d.zip
busybox-3b1a74467a0909a62f26f6f27ac63ea922939c4d.tar.gz
re-indent
Diffstat (limited to 'modutils/modprobe.c')
-rw-r--r--modutils/modprobe.c230
1 files changed, 115 insertions, 115 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index 6b4405a..e300c0d 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -36,20 +36,20 @@
struct dep_t {
char * m_module;
char * m_options;
-
+
int m_isalias : 1;
int m_reserved : 15;
-
+
int m_depcnt : 16;
char ** m_deparr;
-
+
struct dep_t * m_next;
};
struct mod_list_t {
char * m_module;
char * m_options;
-
+
struct mod_list_t * m_prev;
struct mod_list_t * m_next;
};
@@ -74,7 +74,7 @@ int parse_tag_value ( char *buffer, char **ptag, char **pvalue )
*ptag = tag;
*pvalue = value;
-
+
return bb_strlen( tag ) && bb_strlen( value );
}
@@ -85,16 +85,16 @@ int parse_tag_value ( char *buffer, char **ptag, char **pvalue )
static char *reads ( int fd, char *buffer, size_t len )
{
int n = read ( fd, buffer, len );
-
+
if ( n > 0 ) {
char *p;
-
+
buffer [len-1] = 0;
p = strchr ( buffer, '\n' );
-
+
if ( p ) {
off_t offset;
-
+
offset = lseek ( fd, 0L, SEEK_CUR ); // Get the current file descriptor offset
lseek ( fd, offset-n + (p-buffer) + 1, SEEK_SET ); // Set the file descriptor offset to right after the \n
@@ -102,7 +102,7 @@ static char *reads ( int fd, char *buffer, size_t len )
}
return buffer;
}
-
+
else
return 0;
}
@@ -116,11 +116,11 @@ static struct dep_t *build_dep ( void )
char buffer[256];
char *filename = buffer;
int continuation_line = 0;
-
+
k_version = 0;
if ( uname ( &un ))
return 0;
-
+
// check for buffer overflow in following code
if ( bb_strlen ( un.release ) > ( sizeof( buffer ) - 64 )) {
return 0;
@@ -128,7 +128,7 @@ static struct dep_t *build_dep ( void )
if (un.release[0] == '2') {
k_version = un.release[2] - '0';
}
-
+
strcpy ( filename, "/lib/modules/" );
strcat ( filename, un.release );
strcat ( filename, "/modules.dep" );
@@ -144,44 +144,44 @@ static struct dep_t *build_dep ( void )
while ( reads ( fd, buffer, sizeof( buffer ))) {
int l = bb_strlen ( buffer );
char *p = 0;
-
+
while ( isspace ( buffer [l-1] )) {
buffer [l-1] = 0;
l--;
}
-
+
if ( l == 0 ) {
continuation_line = 0;
continue;
}
-
+
if ( !continuation_line ) {
char *col = strchr ( buffer, ':' );
-
+
if ( col ) {
char *mods;
char *mod;
int ext = 0;
-
+
*col = 0;
mods = strrchr ( buffer, '/' );
-
+
if ( !mods )
mods = buffer;
else
mods++;
-
+
#if defined(CONFIG_FEATURE_2_6_MODULES)
if ((k_version > 4) && ( *(col-3) == '.' ) &&
- ( *(col-2) == 'k' ) && ( *(col-1) == 'o' ))
+ ( *(col-2) == 'k' ) && ( *(col-1) == 'o' ))
ext = 3;
else
#endif
- if (( *(col-2) == '.' ) && ( *(col-1) == 'o' ))
- ext = 2;
-
+ if (( *(col-2) == '.' ) && ( *(col-1) == 'o' ))
+ ext = 2;
+
mod = bb_xstrndup ( mods, col - mods - ext );
-
+
if ( !current ) {
first = current = (struct dep_t *) xmalloc ( sizeof ( struct dep_t ));
}
@@ -195,9 +195,9 @@ static struct dep_t *build_dep ( void )
current-> m_depcnt = 0;
current-> m_deparr = 0;
current-> m_next = 0;
-
+
//printf ( "%s:\n", mod );
-
+
p = col + 1;
}
else
@@ -205,49 +205,49 @@ static struct dep_t *build_dep ( void )
}
else
p = buffer;
-
+
if ( p && *p ) {
char *end = &buffer [l-1];
char *deps = strrchr ( end, '/' );
char *dep;
int ext = 0;
-
+
while ( isblank ( *end ) || ( *end == '\\' ))
end--;
-
+
deps = strrchr ( p, '/' );
-
+
if ( !deps || ( deps < p )) {
deps = p;
-
+
while ( isblank ( *deps ))
deps++;
}
else
deps++;
-
+
#if defined(CONFIG_FEATURE_2_6_MODULES)
if ((k_version > 4) && ( *(end-2) == '.' ) && *(end-1) == 'k' &&
- ( *end == 'o' ))
+ ( *end == 'o' ))
ext = 3;
else
#endif
- if (( *(end-1) == '.' ) && ( *end == 'o' ))
- ext = 2;
+ if (( *(end-1) == '.' ) && ( *end == 'o' ))
+ ext = 2;
/* Cope with blank lines */
if ((end-deps-ext+1) <= 0)
continue;
-
+
dep = bb_xstrndup ( deps, end - deps - ext + 1 );
-
+
current-> m_depcnt++;
current-> m_deparr = (char **) xrealloc ( current-> m_deparr, sizeof ( char *) * current-> m_depcnt );
current-> m_deparr [current-> m_depcnt - 1] = dep;
-
+
//printf ( " %d) %s\n", current-> m_depcnt, current-> m_deparr [current-> m_depcnt -1] );
}
-
+
if ( buffer [l-1] == '\\' )
continuation_line = 1;
else
@@ -260,35 +260,35 @@ static struct dep_t *build_dep ( void )
if (( fd = open ( "/etc/modules.conf", O_RDONLY )) < 0 )
if (( fd = open ( "/etc/conf.modules", O_RDONLY )) < 0 )
return first;
-
+
continuation_line = 0;
while ( reads ( fd, buffer, sizeof( buffer ))) {
int l;
char *p;
-
+
p = strchr ( buffer, '#' );
if ( p )
*p = 0;
-
+
l = bb_strlen ( buffer );
-
+
while ( l && isspace ( buffer [l-1] )) {
buffer [l-1] = 0;
l--;
}
-
+
if ( l == 0 ) {
continuation_line = 0;
continue;
}
-
+
if ( !continuation_line ) {
if (( strncmp ( buffer, "alias", 5 ) == 0 ) && isspace ( buffer [5] )) {
char *alias, *mod;
if ( parse_tag_value ( buffer + 6, &alias, &mod )) {
// fprintf ( stderr, "ALIAS: '%s' -> '%s'\n", alias, mod );
-
+
if ( !current ) {
first = current = (struct dep_t *) xmalloc ( sizeof ( struct dep_t ));
}
@@ -298,7 +298,7 @@ static struct dep_t *build_dep ( void )
}
current-> m_module = bb_xstrdup ( alias );
current-> m_isalias = 1;
-
+
if (( strcmp ( alias, "off" ) == 0 ) || ( strcmp ( alias, "null" ) == 0 )) {
current-> m_depcnt = 0;
current-> m_deparr = 0;
@@ -313,10 +313,10 @@ static struct dep_t *build_dep ( void )
}
else if (( strncmp ( buffer, "options", 7 ) == 0 ) && isspace ( buffer [7] )) {
char *mod, *opt;
-
+
if ( parse_tag_value ( buffer + 8, &mod, &opt )) {
struct dep_t *dt;
-
+
for ( dt = first; dt; dt = dt-> m_next ) {
if ( strcmp ( dt-> m_module, mod ) == 0 )
break;
@@ -324,7 +324,7 @@ static struct dep_t *build_dep ( void )
if ( dt ) {
dt-> m_options = xrealloc ( dt-> m_options, bb_strlen( opt ) + 1 );
strcpy ( dt-> m_options, opt );
-
+
// fprintf ( stderr, "OPTION: '%s' -> '%s'\n", dt-> m_module, dt-> m_options );
}
}
@@ -332,7 +332,7 @@ static struct dep_t *build_dep ( void )
}
}
close ( fd );
-
+
return first;
}
@@ -377,7 +377,7 @@ static int mod_process ( struct mod_list_t *list, int do_insert )
if (already_loaded (list->m_module) != 0)
snprintf ( lcmd, sizeof( lcmd ) - 1, "rmmod %s %s", do_syslog ? "-s" : "", list-> m_module );
}
-
+
if ( verbose )
printf ( "%s\n", lcmd );
if ( !show_only && *lcmd) {
@@ -385,7 +385,7 @@ static int mod_process ( struct mod_list_t *list, int do_insert )
if (do_insert) rc = rc2; /* only last module matters */
else if (!rc2) rc = 0; /* success if remove any mod */
}
-
+
list = do_insert ? list-> m_prev : list-> m_next;
}
return (show_only) ? 0 : rc;
@@ -403,12 +403,12 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
#if defined(CONFIG_FEATURE_2_6_MODULES)
if ((k_version > 4) && ( mod [lm-3] == '.' ) &&
- ( mod [lm-2] == 'k' ) && ( mod [lm-1] == 'o' ))
+ ( mod [lm-2] == 'k' ) && ( mod [lm-1] == 'o' ))
mod [lm-3] = 0;
else
#endif
- if (( mod [lm-2] == '.' ) && ( mod [lm-1] == 'o' ))
- mod [lm-2] = 0;
+ if (( mod [lm-2] == '.' ) && ( mod [lm-1] == 'o' ))
+ mod [lm-2] = 0;
// check dependencies
for ( dt = depend; dt; dt = dt-> m_next ) {
@@ -417,12 +417,12 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
break;
}
}
-
+
// resolve alias names
while ( dt && dt-> m_isalias ) {
if ( dt-> m_depcnt == 1 ) {
struct dep_t *adt;
-
+
for ( adt = depend; adt; adt = adt-> m_next ) {
if ( strcmp ( adt-> m_module, dt-> m_deparr [0] ) == 0 )
break;
@@ -439,7 +439,7 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
else
return;
}
-
+
// search for duplicates
for ( find = *head; find; find = find-> m_next ) {
if ( !strcmp ( mod, find-> m_module )) {
@@ -449,12 +449,12 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
find-> m_prev-> m_next = find-> m_next;
else
*head = find-> m_next;
-
+
if ( find-> m_next )
find-> m_next-> m_prev = find-> m_prev;
else
*tail = find-> m_prev;
-
+
break; // there can be only one duplicate
}
}
@@ -474,10 +474,10 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
if ( !*head )
*head = find;
*tail = find;
-
+
if ( dt ) {
int i;
-
+
for ( i = 0; i < dt-> m_depcnt; i++ )
check_dep ( dt-> m_deparr [i], head, tail );
}
@@ -490,34 +490,34 @@ static int mod_insert ( char *mod, int argc, char **argv )
struct mod_list_t *tail = 0;
struct mod_list_t *head = 0;
int rc;
-
+
// get dep list for module mod
check_dep ( mod, &head, &tail );
-
+
if ( head && tail ) {
if ( argc ) {
int i;
int l = 0;
-
+
// append module args
for ( i = 0; i < argc; i++ )
l += ( bb_strlen ( argv [i] ) + 1 );
-
+
head-> m_options = xrealloc ( head-> m_options, l + 1 );
head-> m_options [0] = 0;
-
+
for ( i = 0; i < argc; i++ ) {
strcat ( head-> m_options, argv [i] );
strcat ( head-> m_options, " " );
}
}
-
+
// process tail ---> head
rc = mod_process ( tail, 1 );
}
else
rc = 1;
-
+
return rc;
}
@@ -525,21 +525,21 @@ static int mod_remove ( char *mod )
{
int rc;
static struct mod_list_t rm_a_dummy = { "-a", 0, 0 };
-
+
struct mod_list_t *head = 0;
struct mod_list_t *tail = 0;
-
+
if ( mod )
check_dep ( mod, &head, &tail );
else // autoclean
head = tail = &rm_a_dummy;
-
+
if ( head && tail )
rc = mod_process ( head, 0 ); // process head ---> tail
else
rc = 1;
return rc;
-
+
}
@@ -553,67 +553,67 @@ extern int modprobe_main(int argc, char** argv)
while ((opt = getopt(argc, argv, "acdklnqrst:vVC:")) != -1) {
switch(opt) {
- case 'c': // no config used
- case 'l': // no pattern matching
- return EXIT_SUCCESS;
- break;
- case 'C': // no config used
- case 't': // no pattern matching
- bb_error_msg_and_die("-t and -C not supported");
-
- case 'a': // ignore
- case 'd': // ignore
- break;
- case 'k':
- autoclean++;
- break;
- case 'n':
- show_only++;
- break;
- case 'q':
- quiet++;
- break;
- case 'r':
- remove_opt++;
- break;
- case 's':
- do_syslog++;
- break;
- case 'v':
- verbose++;
- break;
- case 'V':
- default:
- bb_show_usage();
- break;
+ case 'c': // no config used
+ case 'l': // no pattern matching
+ return EXIT_SUCCESS;
+ break;
+ case 'C': // no config used
+ case 't': // no pattern matching
+ bb_error_msg_and_die("-t and -C not supported");
+
+ case 'a': // ignore
+ case 'd': // ignore
+ break;
+ case 'k':
+ autoclean++;
+ break;
+ case 'n':
+ show_only++;
+ break;
+ case 'q':
+ quiet++;
+ break;
+ case 'r':
+ remove_opt++;
+ break;
+ case 's':
+ do_syslog++;
+ break;
+ case 'v':
+ verbose++;
+ break;
+ case 'V':
+ default:
+ bb_show_usage();
+ break;
}
}
-
+
depend = build_dep ( );
if ( !depend )
bb_error_msg_and_die ( "could not parse modules.dep\n" );
-
+
if (remove_opt) {
int rc = EXIT_SUCCESS;
do {
if (mod_remove ( optind < argc ?
- bb_xstrdup (argv [optind]) : NULL )) {
+ bb_xstrdup (argv [optind]) : NULL )) {
bb_error_msg ("failed to remove module %s",
- argv [optind] );
+ argv [optind] );
rc = EXIT_FAILURE;
}
} while ( ++optind < argc );
-
+
return rc;
}
if (optind >= argc)
bb_error_msg_and_die ( "No module or pattern provided\n" );
-
+
if ( mod_insert ( bb_xstrdup ( argv [optind] ), argc - optind - 1, argv + optind + 1 ))
bb_error_msg_and_die ( "failed to load module %s", argv [optind] );
-
+
return EXIT_SUCCESS;
}