diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-27 15:12:50 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-27 15:12:50 +0000 |
commit | cf70433173663a5d627d2a049328cd580f7e9220 (patch) | |
tree | 6580456eb06acacd43ce8515a4719cc43be07184 | |
parent | 82f9e285132a89fb47895a385986a442fe7bb506 (diff) | |
download | busybox-w32-cf70433173663a5d627d2a049328cd580f7e9220.tar.gz busybox-w32-cf70433173663a5d627d2a049328cd580f7e9220.tar.bz2 busybox-w32-cf70433173663a5d627d2a049328cd580f7e9220.zip |
modprobe: reformat to match bbox style
-rw-r--r-- | libbb/kernel_version.c | 7 | ||||
-rw-r--r-- | modutils/modprobe.c | 582 |
2 files changed, 293 insertions, 296 deletions
diff --git a/libbb/kernel_version.c b/libbb/kernel_version.c index e784a049a..50b82ae18 100644 --- a/libbb/kernel_version.c +++ b/libbb/kernel_version.c | |||
@@ -7,9 +7,6 @@ | |||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <stdio.h> | ||
11 | #include <string.h> | ||
12 | #include <stdlib.h> | ||
13 | #include <sys/utsname.h> /* for uname(2) */ | 10 | #include <sys/utsname.h> /* for uname(2) */ |
14 | 11 | ||
15 | #include "libbb.h" | 12 | #include "libbb.h" |
@@ -27,12 +24,12 @@ int get_linux_version_code(void) | |||
27 | 24 | ||
28 | if (uname(&name) == -1) { | 25 | if (uname(&name) == -1) { |
29 | bb_perror_msg("cannot get system information"); | 26 | bb_perror_msg("cannot get system information"); |
30 | return (0); | 27 | return 0; |
31 | } | 28 | } |
32 | 29 | ||
33 | s = name.release; | 30 | s = name.release; |
34 | r = 0; | 31 | r = 0; |
35 | for (i=0 ; i<3 ; i++) { | 32 | for (i = 0; i < 3; i++) { |
36 | r = r * 256 + atoi(strtok(s, ".")); | 33 | r = r * 256 + atoi(strtok(s, ".")); |
37 | s = NULL; | 34 | s = NULL; |
38 | } | 35 | } |
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 08f383c82..dcab493f1 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
@@ -22,17 +22,17 @@ struct mod_opt_t { /* one-way list of options to pass to a module */ | |||
22 | 22 | ||
23 | struct dep_t { /* one-way list of dependency rules */ | 23 | struct dep_t { /* one-way list of dependency rules */ |
24 | /* a dependency rule */ | 24 | /* a dependency rule */ |
25 | char * m_name; /* the module name*/ | 25 | char * m_name; /* the module name*/ |
26 | char * m_path; /* the module file path */ | 26 | char * m_path; /* the module file path */ |
27 | struct mod_opt_t * m_options; /* the module options */ | 27 | struct mod_opt_t * m_options; /* the module options */ |
28 | 28 | ||
29 | int m_isalias : 1; /* the module is an alias */ | 29 | int m_isalias : 1; /* the module is an alias */ |
30 | int m_reserved : 15; /* stuffin' */ | 30 | int m_reserved : 15; /* stuffin' */ |
31 | 31 | ||
32 | int m_depcnt : 16; /* the number of dependable module(s) */ | 32 | int m_depcnt : 16; /* the number of dependable module(s) */ |
33 | char ** m_deparr; /* the list of dependable module(s) */ | 33 | char ** m_deparr; /* the list of dependable module(s) */ |
34 | 34 | ||
35 | struct dep_t * m_next; /* the next dependency rule */ | 35 | struct dep_t * m_next; /* the next dependency rule */ |
36 | }; | 36 | }; |
37 | 37 | ||
38 | struct mod_list_t { /* two-way list of modules to process */ | 38 | struct mod_list_t { /* two-way list of modules to process */ |
@@ -72,17 +72,17 @@ static struct dep_t *depend; | |||
72 | 72 | ||
73 | static int main_opts; | 73 | static int main_opts; |
74 | 74 | ||
75 | static int parse_tag_value ( char *buffer, char **ptag, char **pvalue ) | 75 | static int parse_tag_value(char *buffer, char **ptag, char **pvalue) |
76 | { | 76 | { |
77 | char *tag, *value; | 77 | char *tag, *value; |
78 | 78 | ||
79 | buffer = skip_whitespace ( buffer ); | 79 | buffer = skip_whitespace(buffer); |
80 | tag = value = buffer; | 80 | tag = value = buffer; |
81 | while ( !isspace ( *value )) | 81 | while (!isspace(*value)) |
82 | if (!*value) return 0; | 82 | if (!*value) return 0; |
83 | else value++; | 83 | else value++; |
84 | *value++ = 0; | 84 | *value++ = 0; |
85 | value = skip_whitespace ( value ); | 85 | value = skip_whitespace(value); |
86 | if (!*value) return 0; | 86 | if (!*value) return 0; |
87 | 87 | ||
88 | *ptag = tag; | 88 | *ptag = tag; |
@@ -94,28 +94,28 @@ static int parse_tag_value ( char *buffer, char **ptag, char **pvalue ) | |||
94 | /* | 94 | /* |
95 | * This function appends an option to a list | 95 | * This function appends an option to a list |
96 | */ | 96 | */ |
97 | static struct mod_opt_t *append_option( struct mod_opt_t *opt_list, char *opt ) | 97 | static struct mod_opt_t *append_option(struct mod_opt_t *opt_list, char *opt) |
98 | { | 98 | { |
99 | struct mod_opt_t *ol = opt_list; | 99 | struct mod_opt_t *ol = opt_list; |
100 | 100 | ||
101 | if( ol ) { | 101 | if (ol) { |
102 | while( ol-> m_next ) { | 102 | while (ol->m_next) { |
103 | ol = ol-> m_next; | 103 | ol = ol->m_next; |
104 | } | 104 | } |
105 | ol-> m_next = xmalloc( sizeof( struct mod_opt_t ) ); | 105 | ol->m_next = xmalloc(sizeof(struct mod_opt_t)); |
106 | ol = ol-> m_next; | 106 | ol = ol->m_next; |
107 | } else { | 107 | } else { |
108 | ol = opt_list = xmalloc( sizeof( struct mod_opt_t ) ); | 108 | ol = opt_list = xmalloc(sizeof(struct mod_opt_t)); |
109 | } | 109 | } |
110 | 110 | ||
111 | ol-> m_opt_val = xstrdup( opt ); | 111 | ol->m_opt_val = xstrdup(opt); |
112 | ol-> m_next = NULL; | 112 | ol->m_next = NULL; |
113 | 113 | ||
114 | return opt_list; | 114 | return opt_list; |
115 | } | 115 | } |
116 | 116 | ||
117 | #if ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS | 117 | #if ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS |
118 | /* static char* parse_command_string( char* src, char **dst ); | 118 | /* static char* parse_command_string(char* src, char **dst); |
119 | * src: pointer to string containing argument | 119 | * src: pointer to string containing argument |
120 | * dst: pointer to where to store the parsed argument | 120 | * dst: pointer to where to store the parsed argument |
121 | * return value: the pointer to the first char after the parsed argument, | 121 | * return value: the pointer to the first char after the parsed argument, |
@@ -126,100 +126,100 @@ static struct mod_opt_t *append_option( struct mod_opt_t *opt_list, char *opt ) | |||
126 | #define ARG_EMPTY 0x00 | 126 | #define ARG_EMPTY 0x00 |
127 | #define ARG_IN_DQUOTES 0x01 | 127 | #define ARG_IN_DQUOTES 0x01 |
128 | #define ARG_IN_SQUOTES 0x02 | 128 | #define ARG_IN_SQUOTES 0x02 |
129 | static char *parse_command_string( char *src, char **dst ) | 129 | static char *parse_command_string(char *src, char **dst) |
130 | { | 130 | { |
131 | int opt_status = ARG_EMPTY; | 131 | int opt_status = ARG_EMPTY; |
132 | char* tmp_str; | 132 | char* tmp_str; |
133 | 133 | ||
134 | /* Dumb you, I have nothing to do... */ | 134 | /* Dumb you, I have nothing to do... */ |
135 | if( src == NULL ) return src; | 135 | if (src == NULL) return src; |
136 | 136 | ||
137 | /* Skip leading spaces */ | 137 | /* Skip leading spaces */ |
138 | while( *src == ' ' ) { | 138 | while (*src == ' ') { |
139 | src++; | 139 | src++; |
140 | } | 140 | } |
141 | /* Is the end of string reached? */ | 141 | /* Is the end of string reached? */ |
142 | if( *src == '\0' ) { | 142 | if (*src == '\0') { |
143 | return NULL; | 143 | return NULL; |
144 | } | 144 | } |
145 | /* Reached the start of an argument | 145 | /* Reached the start of an argument |
146 | * By the way, we duplicate a little too much | 146 | * By the way, we duplicate a little too much |
147 | * here but what is too much is freed later. */ | 147 | * here but what is too much is freed later. */ |
148 | *dst = tmp_str = xstrdup( src ); | 148 | *dst = tmp_str = xstrdup(src); |
149 | /* Get to the end of that argument */ | 149 | /* Get to the end of that argument */ |
150 | while( ( *tmp_str != '\0' ) | 150 | while (*tmp_str != '\0' |
151 | && ( ( *tmp_str != ' ' ) | 151 | && (*tmp_str != ' ' || (opt_status & (ARG_IN_DQUOTES | ARG_IN_SQUOTES))) |
152 | || ( opt_status & ( ARG_IN_DQUOTES | ARG_IN_SQUOTES ) ) ) ) { | 152 | ) { |
153 | switch( *tmp_str ) { | 153 | switch (*tmp_str) { |
154 | case '\'': | 154 | case '\'': |
155 | if( opt_status & ARG_IN_DQUOTES ) { | 155 | if (opt_status & ARG_IN_DQUOTES) { |
156 | /* Already in double quotes, keep current char as is */ | 156 | /* Already in double quotes, keep current char as is */ |
157 | } else { | 157 | } else { |
158 | /* shift left 1 char, until end of string: get rid of the opening/closing quotes */ | 158 | /* shift left 1 char, until end of string: get rid of the opening/closing quotes */ |
159 | memmove( tmp_str, tmp_str + 1, strlen( tmp_str ) ); | 159 | memmove(tmp_str, tmp_str + 1, strlen(tmp_str)); |
160 | /* mark me: we enter or leave single quotes */ | 160 | /* mark me: we enter or leave single quotes */ |
161 | opt_status ^= ARG_IN_SQUOTES; | 161 | opt_status ^= ARG_IN_SQUOTES; |
162 | /* Back one char, as we need to re-scan the new char there. */ | 162 | /* Back one char, as we need to re-scan the new char there. */ |
163 | tmp_str--; | 163 | tmp_str--; |
164 | } | 164 | } |
165 | break; | 165 | break; |
166 | case '"': | 166 | case '"': |
167 | if( opt_status & ARG_IN_SQUOTES ) { | 167 | if (opt_status & ARG_IN_SQUOTES) { |
168 | /* Already in single quotes, keep current char as is */ | 168 | /* Already in single quotes, keep current char as is */ |
169 | } else { | 169 | } else { |
170 | /* shift left 1 char, until end of string: get rid of the opening/closing quotes */ | 170 | /* shift left 1 char, until end of string: get rid of the opening/closing quotes */ |
171 | memmove( tmp_str, tmp_str + 1, strlen( tmp_str ) ); | 171 | memmove(tmp_str, tmp_str + 1, strlen(tmp_str)); |
172 | /* mark me: we enter or leave double quotes */ | 172 | /* mark me: we enter or leave double quotes */ |
173 | opt_status ^= ARG_IN_DQUOTES; | 173 | opt_status ^= ARG_IN_DQUOTES; |
174 | /* Back one char, as we need to re-scan the new char there. */ | 174 | /* Back one char, as we need to re-scan the new char there. */ |
175 | tmp_str--; | 175 | tmp_str--; |
176 | } | 176 | } |
177 | break; | 177 | break; |
178 | case '\\': | 178 | case '\\': |
179 | if( opt_status & ARG_IN_SQUOTES ) { | 179 | if (opt_status & ARG_IN_SQUOTES) { |
180 | /* Between single quotes: keep as is. */ | 180 | /* Between single quotes: keep as is. */ |
181 | } else { | 181 | } else { |
182 | switch( *(tmp_str+1) ) { | 182 | switch (*(tmp_str+1)) { |
183 | case 'a': | 183 | case 'a': |
184 | case 'b': | 184 | case 'b': |
185 | case 't': | 185 | case 't': |
186 | case 'n': | 186 | case 'n': |
187 | case 'v': | 187 | case 'v': |
188 | case 'f': | 188 | case 'f': |
189 | case 'r': | 189 | case 'r': |
190 | case '0': | 190 | case '0': |
191 | /* We escaped a special character. For now, keep | 191 | /* We escaped a special character. For now, keep |
192 | * both the back-slash and the following char. */ | 192 | * both the back-slash and the following char. */ |
193 | tmp_str++; src++; | 193 | tmp_str++; src++; |
194 | break; | 194 | break; |
195 | default: | 195 | default: |
196 | /* We escaped a space or a single or double quote, | 196 | /* We escaped a space or a single or double quote, |
197 | * or a back-slash, or a non-escapable char. Remove | 197 | * or a back-slash, or a non-escapable char. Remove |
198 | * the '\' and keep the new current char as is. */ | 198 | * the '\' and keep the new current char as is. */ |
199 | memmove( tmp_str, tmp_str + 1, strlen( tmp_str ) ); | 199 | memmove(tmp_str, tmp_str + 1, strlen(tmp_str)); |
200 | break; | 200 | break; |
201 | } | ||
202 | } | 201 | } |
202 | } | ||
203 | break; | ||
204 | /* Any other char that is special shall appear here. | ||
205 | * Example: $ starts a variable | ||
206 | case '$': | ||
207 | do_variable_expansion(); | ||
208 | break; | ||
209 | * */ | ||
210 | default: | ||
211 | /* any other char is kept as is. */ | ||
203 | break; | 212 | break; |
204 | /* Any other char that is special shall appear here. | ||
205 | * Example: $ starts a variable | ||
206 | case '$': | ||
207 | do_variable_expansion(); | ||
208 | break; | ||
209 | * */ | ||
210 | default: | ||
211 | /* any other char is kept as is. */ | ||
212 | break; | ||
213 | } | 213 | } |
214 | tmp_str++; /* Go to next char */ | 214 | tmp_str++; /* Go to next char */ |
215 | src++; /* Go to next char to find the end of the argument. */ | 215 | src++; /* Go to next char to find the end of the argument. */ |
216 | } | 216 | } |
217 | /* End of string, but still no ending quote */ | 217 | /* End of string, but still no ending quote */ |
218 | if( opt_status & ( ARG_IN_DQUOTES | ARG_IN_SQUOTES ) ) { | 218 | if (opt_status & (ARG_IN_DQUOTES | ARG_IN_SQUOTES)) { |
219 | bb_error_msg_and_die( "unterminated (single or double) quote in options list: %s", src ); | 219 | bb_error_msg_and_die("unterminated (single or double) quote in options list: %s", src); |
220 | } | 220 | } |
221 | *tmp_str++ = '\0'; | 221 | *tmp_str++ = '\0'; |
222 | *dst = xrealloc( *dst, (tmp_str - *dst ) ); | 222 | *dst = xrealloc(*dst, (tmp_str - *dst)); |
223 | return src; | 223 | return src; |
224 | } | 224 | } |
225 | #else | 225 | #else |
@@ -230,90 +230,90 @@ static char *parse_command_string( char *src, char **dst ) | |||
230 | * This function reads aliases and default module options from a configuration file | 230 | * This function reads aliases and default module options from a configuration file |
231 | * (/etc/modprobe.conf syntax). It supports includes (only files, no directories). | 231 | * (/etc/modprobe.conf syntax). It supports includes (only files, no directories). |
232 | */ | 232 | */ |
233 | static void include_conf ( struct dep_t **first, struct dep_t **current, char *buffer, int buflen, int fd ) | 233 | static void include_conf(struct dep_t **first, struct dep_t **current, char *buffer, int buflen, int fd) |
234 | { | 234 | { |
235 | int continuation_line = 0; | 235 | int continuation_line = 0; |
236 | 236 | ||
237 | // alias parsing is not 100% correct (no correct handling of continuation lines within an alias) ! | 237 | // alias parsing is not 100% correct (no correct handling of continuation lines within an alias) ! |
238 | 238 | ||
239 | while ( reads ( fd, buffer, buflen)) { | 239 | while (reads(fd, buffer, buflen)) { |
240 | int l; | 240 | int l; |
241 | char *p; | 241 | char *p; |
242 | 242 | ||
243 | p = strchr ( buffer, '#' ); | 243 | p = strchr(buffer, '#'); |
244 | if ( p ) | 244 | if (p) |
245 | *p = 0; | 245 | *p = 0; |
246 | 246 | ||
247 | l = strlen ( buffer ); | 247 | l = strlen(buffer); |
248 | 248 | ||
249 | while ( l && isspace ( buffer [l-1] )) { | 249 | while (l && isspace(buffer[l-1])) { |
250 | buffer [l-1] = 0; | 250 | buffer[l-1] = 0; |
251 | l--; | 251 | l--; |
252 | } | 252 | } |
253 | 253 | ||
254 | if ( l == 0 ) { | 254 | if (l == 0) { |
255 | continuation_line = 0; | 255 | continuation_line = 0; |
256 | continue; | 256 | continue; |
257 | } | 257 | } |
258 | 258 | ||
259 | if ( !continuation_line ) { | 259 | if (!continuation_line) { |
260 | if (( strncmp ( buffer, "alias", 5 ) == 0 ) && isspace ( buffer [5] )) { | 260 | if ((strncmp(buffer, "alias", 5) == 0) && isspace(buffer[5])) { |
261 | char *alias, *mod; | 261 | char *alias, *mod; |
262 | 262 | ||
263 | if ( parse_tag_value ( buffer + 6, &alias, &mod )) { | 263 | if (parse_tag_value(buffer + 6, &alias, &mod)) { |
264 | /* handle alias as a module dependent on the aliased module */ | 264 | /* handle alias as a module dependent on the aliased module */ |
265 | if ( !*current ) { | 265 | if (!*current) { |
266 | (*first) = (*current) = (struct dep_t *) xzalloc (sizeof ( struct dep_t )); | 266 | (*first) = (*current) = xzalloc(sizeof(struct dep_t)); |
267 | } | 267 | } |
268 | else { | 268 | else { |
269 | (*current)-> m_next = (struct dep_t *) xzalloc (sizeof ( struct dep_t )); | 269 | (*current)->m_next = xzalloc(sizeof(struct dep_t)); |
270 | (*current) = (*current)-> m_next; | 270 | (*current) = (*current)->m_next; |
271 | } | 271 | } |
272 | (*current)-> m_name = xstrdup ( alias ); | 272 | (*current)->m_name = xstrdup(alias); |
273 | (*current)-> m_isalias = 1; | 273 | (*current)->m_isalias = 1; |
274 | 274 | ||
275 | if (( strcmp ( mod, "off" ) == 0 ) || ( strcmp ( mod, "null" ) == 0 )) { | 275 | if ((strcmp(mod, "off") == 0) || (strcmp(mod, "null") == 0)) { |
276 | (*current)-> m_depcnt = 0; | 276 | (*current)->m_depcnt = 0; |
277 | (*current)-> m_deparr = 0; | 277 | (*current)->m_deparr = 0; |
278 | } | 278 | } |
279 | else { | 279 | else { |
280 | (*current)-> m_depcnt = 1; | 280 | (*current)->m_depcnt = 1; |
281 | (*current)-> m_deparr = xmalloc ( 1 * sizeof( char * )); | 281 | (*current)->m_deparr = xmalloc(1 * sizeof(char *)); |
282 | (*current)-> m_deparr[0] = xstrdup ( mod ); | 282 | (*current)->m_deparr[0] = xstrdup(mod); |
283 | } | 283 | } |
284 | (*current)-> m_next = 0; | 284 | (*current)->m_next = 0; |
285 | } | 285 | } |
286 | } | 286 | } |
287 | else if (( strncmp ( buffer, "options", 7 ) == 0 ) && isspace ( buffer [7] )) { | 287 | else if ((strncmp(buffer, "options", 7) == 0) && isspace(buffer[7])) { |
288 | char *mod, *opt; | 288 | char *mod, *opt; |
289 | 289 | ||
290 | /* split the line in the module/alias name, and options */ | 290 | /* split the line in the module/alias name, and options */ |
291 | if ( parse_tag_value ( buffer + 8, &mod, &opt )) { | 291 | if (parse_tag_value(buffer + 8, &mod, &opt)) { |
292 | struct dep_t *dt; | 292 | struct dep_t *dt; |
293 | 293 | ||
294 | /* find the corresponding module */ | 294 | /* find the corresponding module */ |
295 | for ( dt = *first; dt; dt = dt-> m_next ) { | 295 | for (dt = *first; dt; dt = dt->m_next) { |
296 | if ( strcmp ( dt-> m_name, mod ) == 0 ) | 296 | if (strcmp(dt->m_name, mod) == 0) |
297 | break; | 297 | break; |
298 | } | 298 | } |
299 | if ( dt ) { | 299 | if (dt) { |
300 | if ( ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS ) { | 300 | if (ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS) { |
301 | char* new_opt = NULL; | 301 | char* new_opt = NULL; |
302 | while( ( opt = parse_command_string( opt, &new_opt ) ) ) { | 302 | while ((opt = parse_command_string(opt, &new_opt))) { |
303 | dt-> m_options = append_option( dt-> m_options, new_opt ); | 303 | dt->m_options = append_option(dt->m_options, new_opt); |
304 | } | 304 | } |
305 | } else { | 305 | } else { |
306 | dt-> m_options = append_option( dt-> m_options, opt ); | 306 | dt->m_options = append_option(dt->m_options, opt); |
307 | } | 307 | } |
308 | } | 308 | } |
309 | } | 309 | } |
310 | } | 310 | } |
311 | else if (( strncmp ( buffer, "include", 7 ) == 0 ) && isspace ( buffer [7] )) { | 311 | else if ((strncmp(buffer, "include", 7) == 0) && isspace(buffer[7])) { |
312 | int fdi; char *filename; | 312 | int fdi; char *filename; |
313 | 313 | ||
314 | filename = skip_whitespace ( buffer + 8 ); | 314 | filename = skip_whitespace(buffer + 8); |
315 | 315 | ||
316 | if (( fdi = open ( filename, O_RDONLY )) >= 0 ) { | 316 | if ((fdi = open(filename, O_RDONLY)) >= 0) { |
317 | include_conf(first, current, buffer, buflen, fdi); | 317 | include_conf(first, current, buffer, buflen, fdi); |
318 | close(fdi); | 318 | close(fdi); |
319 | } | 319 | } |
@@ -327,7 +327,7 @@ static void include_conf ( struct dep_t **first, struct dep_t **current, char *b | |||
327 | * It then fills every modules and aliases with their default options, found by parsing | 327 | * It then fills every modules and aliases with their default options, found by parsing |
328 | * modprobe.conf (or modules.conf, or conf.modules). | 328 | * modprobe.conf (or modules.conf, or conf.modules). |
329 | */ | 329 | */ |
330 | static struct dep_t *build_dep ( void ) | 330 | static struct dep_t *build_dep(void) |
331 | { | 331 | { |
332 | int fd; | 332 | int fd; |
333 | struct utsname un; | 333 | struct utsname un; |
@@ -338,46 +338,47 @@ static struct dep_t *build_dep ( void ) | |||
338 | int continuation_line = 0; | 338 | int continuation_line = 0; |
339 | int k_version; | 339 | int k_version; |
340 | 340 | ||
341 | k_version = 0; | 341 | if (uname(&un)) |
342 | if ( uname ( &un )) | ||
343 | bb_error_msg_and_die("can't determine kernel version"); | 342 | bb_error_msg_and_die("can't determine kernel version"); |
344 | 343 | ||
344 | k_version = 0; | ||
345 | if (un.release[0] == '2') { | 345 | if (un.release[0] == '2') { |
346 | k_version = un.release[2] - '0'; | 346 | k_version = un.release[2] - '0'; |
347 | } | 347 | } |
348 | 348 | ||
349 | filename = xasprintf("/lib/modules/%s/modules.dep", un.release ); | 349 | filename = xasprintf("/lib/modules/%s/modules.dep", un.release); |
350 | fd = open ( filename, O_RDONLY ); | 350 | fd = open(filename, O_RDONLY); |
351 | if (ENABLE_FEATURE_CLEAN_UP) | 351 | if (ENABLE_FEATURE_CLEAN_UP) |
352 | free(filename); | 352 | free(filename); |
353 | if (fd < 0) { | 353 | if (fd < 0) { |
354 | /* Ok, that didn't work. Fall back to looking in /lib/modules */ | 354 | /* Ok, that didn't work. Fall back to looking in /lib/modules */ |
355 | if (( fd = open ( "/lib/modules/modules.dep", O_RDONLY )) < 0 ) { | 355 | fd = open("/lib/modules/modules.dep", O_RDONLY); |
356 | if (fd < 0) { | ||
356 | return 0; | 357 | return 0; |
357 | } | 358 | } |
358 | } | 359 | } |
359 | 360 | ||
360 | while ( reads ( fd, buffer, sizeof( buffer ))) { | 361 | while (reads(fd, buffer, sizeof(buffer))) { |
361 | int l = strlen ( buffer ); | 362 | int l = strlen(buffer); |
362 | char *p = 0; | 363 | char *p = 0; |
363 | 364 | ||
364 | while ( l > 0 && isspace ( buffer [l-1] )) { | 365 | while (l > 0 && isspace(buffer[l-1])) { |
365 | buffer [l-1] = 0; | 366 | buffer[l-1] = 0; |
366 | l--; | 367 | l--; |
367 | } | 368 | } |
368 | 369 | ||
369 | if ( l == 0 ) { | 370 | if (l == 0) { |
370 | continuation_line = 0; | 371 | continuation_line = 0; |
371 | continue; | 372 | continue; |
372 | } | 373 | } |
373 | 374 | ||
374 | /* Is this a new module dep description? */ | 375 | /* Is this a new module dep description? */ |
375 | if ( !continuation_line ) { | 376 | if (!continuation_line) { |
376 | /* find the dep beginning */ | 377 | /* find the dep beginning */ |
377 | char *col = strchr ( buffer, ':' ); | 378 | char *col = strchr(buffer, ':'); |
378 | char *dot = col; | 379 | char *dot = col; |
379 | 380 | ||
380 | if ( col ) { | 381 | if (col) { |
381 | /* This line is a dep description */ | 382 | /* This line is a dep description */ |
382 | char *mods; | 383 | char *mods; |
383 | char *modpath; | 384 | char *modpath; |
@@ -385,43 +386,43 @@ static struct dep_t *build_dep ( void ) | |||
385 | 386 | ||
386 | /* Find the beginning of the module file name */ | 387 | /* Find the beginning of the module file name */ |
387 | *col = 0; | 388 | *col = 0; |
388 | mods = strrchr ( buffer, '/' ); | 389 | mods = strrchr(buffer, '/'); |
389 | 390 | ||
390 | if ( !mods ) | 391 | if (!mods) |
391 | mods = buffer; /* no path for this module */ | 392 | mods = buffer; /* no path for this module */ |
392 | else | 393 | else |
393 | mods++; /* there was a path for this module... */ | 394 | mods++; /* there was a path for this module... */ |
394 | 395 | ||
395 | /* find the path of the module */ | 396 | /* find the path of the module */ |
396 | modpath = strchr ( buffer, '/' ); /* ... and this is the path */ | 397 | modpath = strchr(buffer, '/'); /* ... and this is the path */ |
397 | if ( !modpath ) | 398 | if (!modpath) |
398 | modpath = buffer; /* module with no path */ | 399 | modpath = buffer; /* module with no path */ |
399 | /* find the end of the module name in the file name */ | 400 | /* find the end of the module name in the file name */ |
400 | if ( ENABLE_FEATURE_2_6_MODULES && | 401 | if (ENABLE_FEATURE_2_6_MODULES && |
401 | (k_version > 4) && ( *(col-3) == '.' ) && | 402 | (k_version > 4) && (*(col-3) == '.') && |
402 | ( *(col-2) == 'k' ) && ( *(col-1) == 'o' ) ) | 403 | (*(col-2) == 'k') && (*(col-1) == 'o')) |
403 | dot = col - 3; | 404 | dot = col - 3; |
404 | else | 405 | else |
405 | if (( *(col-2) == '.' ) && ( *(col-1) == 'o' )) | 406 | if ((*(col-2) == '.') && (*(col-1) == 'o')) |
406 | dot = col - 2; | 407 | dot = col - 2; |
407 | 408 | ||
408 | mod = xstrndup ( mods, dot - mods ); | 409 | mod = xstrndup(mods, dot - mods); |
409 | 410 | ||
410 | /* enqueue new module */ | 411 | /* enqueue new module */ |
411 | if ( !current ) { | 412 | if (!current) { |
412 | first = current = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); | 413 | first = current = xmalloc(sizeof(struct dep_t)); |
413 | } | 414 | } |
414 | else { | 415 | else { |
415 | current-> m_next = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); | 416 | current->m_next = xmalloc(sizeof(struct dep_t)); |
416 | current = current-> m_next; | 417 | current = current->m_next; |
417 | } | 418 | } |
418 | current-> m_name = mod; | 419 | current->m_name = mod; |
419 | current-> m_path = xstrdup(modpath); | 420 | current->m_path = xstrdup(modpath); |
420 | current-> m_options = NULL; | 421 | current->m_options = NULL; |
421 | current-> m_isalias = 0; | 422 | current->m_isalias = 0; |
422 | current-> m_depcnt = 0; | 423 | current->m_depcnt = 0; |
423 | current-> m_deparr = 0; | 424 | current->m_deparr = 0; |
424 | current-> m_next = 0; | 425 | current->m_next = 0; |
425 | 426 | ||
426 | p = col + 1; | 427 | p = col + 1; |
427 | } | 428 | } |
@@ -433,26 +434,24 @@ static struct dep_t *build_dep ( void ) | |||
433 | /* It's a dep description continuation */ | 434 | /* It's a dep description continuation */ |
434 | p = buffer; | 435 | p = buffer; |
435 | 436 | ||
436 | while ( p && *p && isblank(*p)) | 437 | while (p && *p && isblank(*p)) |
437 | p++; | 438 | p++; |
438 | 439 | ||
439 | /* p points to the first dependable module; if NULL, no dependable module */ | 440 | /* p points to the first dependable module; if NULL, no dependable module */ |
440 | if ( p && *p ) { | 441 | if (p && *p) { |
441 | char *end = &buffer [l-1]; | 442 | char *end = &buffer[l-1]; |
442 | char *deps; | 443 | char *deps; |
443 | char *dep; | 444 | char *dep; |
444 | char *next; | 445 | char *next; |
445 | int ext = 0; | 446 | int ext = 0; |
446 | 447 | ||
447 | while ( isblank ( *end ) || ( *end == '\\' )) | 448 | while (isblank(*end) || (*end == '\\')) |
448 | end--; | 449 | end--; |
449 | 450 | ||
450 | do | 451 | do { |
451 | { | ||
452 | /* search the end of the dependency */ | 452 | /* search the end of the dependency */ |
453 | next = strchr (p, ' ' ); | 453 | next = strchr(p, ' '); |
454 | if (next) | 454 | if (next) { |
455 | { | ||
456 | *next = 0; | 455 | *next = 0; |
457 | next--; | 456 | next--; |
458 | } | 457 | } |
@@ -460,60 +459,59 @@ static struct dep_t *build_dep ( void ) | |||
460 | next = end; | 459 | next = end; |
461 | 460 | ||
462 | /* find the beginning of the module file name */ | 461 | /* find the beginning of the module file name */ |
463 | deps = strrchr ( p, '/' ); | 462 | deps = strrchr(p, '/'); |
464 | 463 | ||
465 | if ( !deps || ( deps < p )) { | 464 | if (!deps || (deps < p)) { |
466 | deps = p; | 465 | deps = p; |
467 | 466 | ||
468 | while ( isblank ( *deps )) | 467 | while (isblank(*deps)) |
469 | deps++; | 468 | deps++; |
470 | } | 469 | } else |
471 | else | ||
472 | deps++; | 470 | deps++; |
473 | 471 | ||
474 | /* find the end of the module name in the file name */ | 472 | /* find the end of the module name in the file name */ |
475 | if ( ENABLE_FEATURE_2_6_MODULES && | 473 | if (ENABLE_FEATURE_2_6_MODULES |
476 | (k_version > 4) && ( *(next-2) == '.' ) && | 474 | && (k_version > 4) && (*(next-2) == '.') |
477 | ( *(next-1) == 'k' ) && ( *next == 'o' ) ) | 475 | && (*(next-1) == 'k') && (*next == 'o')) |
478 | ext = 3; | 476 | ext = 3; |
479 | else | 477 | else |
480 | if (( *(next-1) == '.' ) && ( *next == 'o' )) | 478 | if ((*(next-1) == '.') && (*next == 'o')) |
481 | ext = 2; | 479 | ext = 2; |
482 | 480 | ||
483 | /* Cope with blank lines */ | 481 | /* Cope with blank lines */ |
484 | if ((next-deps-ext+1) <= 0) | 482 | if ((next-deps-ext+1) <= 0) |
485 | continue; | 483 | continue; |
486 | dep = xstrndup ( deps, next - deps - ext + 1 ); | 484 | dep = xstrndup(deps, next - deps - ext + 1); |
487 | 485 | ||
488 | /* Add the new dependable module name */ | 486 | /* Add the new dependable module name */ |
489 | current-> m_depcnt++; | 487 | current->m_depcnt++; |
490 | current-> m_deparr = (char **) xrealloc ( current-> m_deparr, | 488 | current->m_deparr = xrealloc(current->m_deparr, |
491 | sizeof ( char *) * current-> m_depcnt ); | 489 | sizeof(char *) * current->m_depcnt); |
492 | current-> m_deparr [current-> m_depcnt - 1] = dep; | 490 | current->m_deparr[current->m_depcnt - 1] = dep; |
493 | 491 | ||
494 | p = next + 2; | 492 | p = next + 2; |
495 | } while (next < end); | 493 | } while (next < end); |
496 | } | 494 | } |
497 | 495 | ||
498 | /* is there other dependable module(s) ? */ | 496 | /* is there other dependable module(s) ? */ |
499 | if ( buffer [l-1] == '\\' ) | 497 | if (buffer[l-1] == '\\') |
500 | continuation_line = 1; | 498 | continuation_line = 1; |
501 | else | 499 | else |
502 | continuation_line = 0; | 500 | continuation_line = 0; |
503 | } | 501 | } |
504 | close ( fd ); | 502 | close(fd); |
505 | 503 | ||
506 | /* | 504 | /* |
507 | * First parse system-specific options and aliases | 505 | * First parse system-specific options and aliases |
508 | * as they take precedence over the kernel ones. | 506 | * as they take precedence over the kernel ones. |
509 | */ | 507 | */ |
510 | if (!ENABLE_FEATURE_2_6_MODULES | 508 | if (!ENABLE_FEATURE_2_6_MODULES |
511 | || ( fd = open ( "/etc/modprobe.conf", O_RDONLY )) < 0 ) | 509 | || (fd = open("/etc/modprobe.conf", O_RDONLY)) < 0) |
512 | if (( fd = open ( "/etc/modules.conf", O_RDONLY )) < 0 ) | 510 | if ((fd = open("/etc/modules.conf", O_RDONLY)) < 0) |
513 | fd = open ( "/etc/conf.modules", O_RDONLY ); | 511 | fd = open("/etc/conf.modules", O_RDONLY); |
514 | 512 | ||
515 | if (fd >= 0) { | 513 | if (fd >= 0) { |
516 | include_conf (&first, ¤t, buffer, sizeof(buffer), fd); | 514 | include_conf(&first, ¤t, buffer, sizeof(buffer), fd); |
517 | close(fd); | 515 | close(fd); |
518 | } | 516 | } |
519 | 517 | ||
@@ -521,15 +519,16 @@ static struct dep_t *build_dep ( void ) | |||
521 | if (ENABLE_FEATURE_2_6_MODULES) { | 519 | if (ENABLE_FEATURE_2_6_MODULES) { |
522 | /* Parse kernel-declared aliases */ | 520 | /* Parse kernel-declared aliases */ |
523 | filename = xasprintf("/lib/modules/%s/modules.alias", un.release); | 521 | filename = xasprintf("/lib/modules/%s/modules.alias", un.release); |
524 | if ((fd = open ( filename, O_RDONLY )) < 0) { | 522 | fd = open(filename, O_RDONLY); |
523 | if (fd < 0) { | ||
525 | /* Ok, that didn't work. Fall back to looking in /lib/modules */ | 524 | /* Ok, that didn't work. Fall back to looking in /lib/modules */ |
526 | fd = open ( "/lib/modules/modules.alias", O_RDONLY ); | 525 | fd = open("/lib/modules/modules.alias", O_RDONLY); |
527 | } | 526 | } |
528 | if (ENABLE_FEATURE_CLEAN_UP) | 527 | if (ENABLE_FEATURE_CLEAN_UP) |
529 | free(filename); | 528 | free(filename); |
530 | 529 | ||
531 | if (fd >= 0) { | 530 | if (fd >= 0) { |
532 | include_conf (&first, ¤t, buffer, sizeof(buffer), fd); | 531 | include_conf(&first, ¤t, buffer, sizeof(buffer), fd); |
533 | close(fd); | 532 | close(fd); |
534 | } | 533 | } |
535 | } | 534 | } |
@@ -538,16 +537,16 @@ static struct dep_t *build_dep ( void ) | |||
538 | } | 537 | } |
539 | 538 | ||
540 | /* return 1 = loaded, 0 = not loaded, -1 = can't tell */ | 539 | /* return 1 = loaded, 0 = not loaded, -1 = can't tell */ |
541 | static int already_loaded (const char *name) | 540 | static int already_loaded(const char *name) |
542 | { | 541 | { |
543 | int fd, ret = 0; | 542 | int fd, ret = 0; |
544 | char buffer[4096]; | 543 | char buffer[4096]; |
545 | 544 | ||
546 | fd = open ("/proc/modules", O_RDONLY); | 545 | fd = open("/proc/modules", O_RDONLY); |
547 | if (fd < 0) | 546 | if (fd < 0) |
548 | return -1; | 547 | return -1; |
549 | 548 | ||
550 | while ( reads ( fd, buffer, sizeof( buffer ))) { | 549 | while (reads(fd, buffer, sizeof(buffer))) { |
551 | char *p; | 550 | char *p; |
552 | 551 | ||
553 | p = strchr (buffer, ' '); | 552 | p = strchr (buffer, ' '); |
@@ -578,7 +577,7 @@ done: | |||
578 | return ret; | 577 | return ret; |
579 | } | 578 | } |
580 | 579 | ||
581 | static int mod_process ( struct mod_list_t *list, int do_insert ) | 580 | static int mod_process(struct mod_list_t *list, int do_insert) |
582 | { | 581 | { |
583 | int rc = 0; | 582 | int rc = 0; |
584 | char **argv = NULL; | 583 | char **argv = NULL; |
@@ -586,9 +585,9 @@ static int mod_process ( struct mod_list_t *list, int do_insert ) | |||
586 | int argc_malloc; /* never used when CONFIG_FEATURE_CLEAN_UP not defined */ | 585 | int argc_malloc; /* never used when CONFIG_FEATURE_CLEAN_UP not defined */ |
587 | int argc; | 586 | int argc; |
588 | 587 | ||
589 | while ( list ) { | 588 | while (list) { |
590 | argc = 0; | 589 | argc = 0; |
591 | if( ENABLE_FEATURE_CLEAN_UP ) | 590 | if (ENABLE_FEATURE_CLEAN_UP) |
592 | argc_malloc = 0; | 591 | argc_malloc = 0; |
593 | /* If CONFIG_FEATURE_CLEAN_UP is not defined, then we leak memory | 592 | /* If CONFIG_FEATURE_CLEAN_UP is not defined, then we leak memory |
594 | * each time we allocate memory for argv. | 593 | * each time we allocate memory for argv. |
@@ -601,9 +600,9 @@ static int mod_process ( struct mod_list_t *list, int do_insert ) | |||
601 | * would not load because there is no more memory, so there's no | 600 | * would not load because there is no more memory, so there's no |
602 | * problem. */ | 601 | * problem. */ |
603 | /* enough for minimal insmod (5 args + NULL) or rmmod (3 args + NULL) */ | 602 | /* enough for minimal insmod (5 args + NULL) or rmmod (3 args + NULL) */ |
604 | argv = (char**) malloc( 6 * sizeof( char* ) ); | 603 | argv = xmalloc(6 * sizeof(char*)); |
605 | if ( do_insert ) { | 604 | if (do_insert) { |
606 | if (already_loaded (list->m_name) != 1) { | 605 | if (already_loaded(list->m_name) != 1) { |
607 | argv[argc++] = "insmod"; | 606 | argv[argc++] = "insmod"; |
608 | if (ENABLE_FEATURE_2_4_MODULES) { | 607 | if (ENABLE_FEATURE_2_4_MODULES) { |
609 | if (do_syslog) | 608 | if (do_syslog) |
@@ -612,29 +611,29 @@ static int mod_process ( struct mod_list_t *list, int do_insert ) | |||
612 | argv[argc++] = "-k"; | 611 | argv[argc++] = "-k"; |
613 | if (quiet) | 612 | if (quiet) |
614 | argv[argc++] = "-q"; | 613 | argv[argc++] = "-q"; |
615 | else if(verbose) /* verbose and quiet are mutually exclusive */ | 614 | else if (verbose) /* verbose and quiet are mutually exclusive */ |
616 | argv[argc++] = "-v"; | 615 | argv[argc++] = "-v"; |
617 | } | 616 | } |
618 | argv[argc++] = list-> m_path; | 617 | argv[argc++] = list->m_path; |
619 | if( ENABLE_FEATURE_CLEAN_UP ) | 618 | if (ENABLE_FEATURE_CLEAN_UP) |
620 | argc_malloc = argc; | 619 | argc_malloc = argc; |
621 | opts = list-> m_options; | 620 | opts = list->m_options; |
622 | while( opts ) { | 621 | while (opts) { |
623 | /* Add one more option */ | 622 | /* Add one more option */ |
624 | argc++; | 623 | argc++; |
625 | argv = (char**) xrealloc( argv, ( argc + 1 ) * sizeof( char* ) ); | 624 | argv = xrealloc(argv,(argc + 1)* sizeof(char*)); |
626 | argv[argc-1] = opts-> m_opt_val; | 625 | argv[argc-1] = opts->m_opt_val; |
627 | opts = opts-> m_next; | 626 | opts = opts->m_next; |
628 | } | 627 | } |
629 | } | 628 | } |
630 | } else { | 629 | } else { |
631 | /* modutils uses short name for removal */ | 630 | /* modutils uses short name for removal */ |
632 | if (already_loaded (list->m_name) != 0) { | 631 | if (already_loaded(list->m_name) != 0) { |
633 | argv[argc++] = "rmmod"; | 632 | argv[argc++] = "rmmod"; |
634 | if (do_syslog) | 633 | if (do_syslog) |
635 | argv[argc++] = "-s"; | 634 | argv[argc++] = "-s"; |
636 | argv[argc++] = list->m_name; | 635 | argv[argc++] = list->m_name; |
637 | if( ENABLE_FEATURE_CLEAN_UP ) | 636 | if (ENABLE_FEATURE_CLEAN_UP) |
638 | argc_malloc = argc; | 637 | argc_malloc = argc; |
639 | } | 638 | } |
640 | } | 639 | } |
@@ -642,7 +641,7 @@ static int mod_process ( struct mod_list_t *list, int do_insert ) | |||
642 | 641 | ||
643 | if (argc) { | 642 | if (argc) { |
644 | if (verbose) { | 643 | if (verbose) { |
645 | printf("%s module %s\n", do_insert?"Loading":"Unloading", list-> m_name ); | 644 | printf("%s module %s\n", do_insert?"Loading":"Unloading", list->m_name); |
646 | } | 645 | } |
647 | if (!show_only) { | 646 | if (!show_only) { |
648 | int rc2 = wait4pid(spawn(argv)); | 647 | int rc2 = wait4pid(spawn(argv)); |
@@ -654,18 +653,19 @@ static int mod_process ( struct mod_list_t *list, int do_insert ) | |||
654 | rc = 0; /* success if remove any mod */ | 653 | rc = 0; /* success if remove any mod */ |
655 | } | 654 | } |
656 | } | 655 | } |
657 | if( ENABLE_FEATURE_CLEAN_UP ) | 656 | if (ENABLE_FEATURE_CLEAN_UP) { |
658 | /* the last value in the array has index == argc, but | 657 | /* the last value in the array has index == argc, but |
659 | * it is the terminating NULL, so we must not free it. */ | 658 | * it is the terminating NULL, so we must not free it. */ |
660 | while( argc_malloc < argc ) { | 659 | while (argc_malloc < argc) { |
661 | free( argv[argc_malloc++] ); | 660 | free(argv[argc_malloc++]); |
661 | } | ||
662 | } | 662 | } |
663 | } | 663 | } |
664 | if( ENABLE_FEATURE_CLEAN_UP ) { | 664 | if (ENABLE_FEATURE_CLEAN_UP) { |
665 | free( argv ); | 665 | free(argv); |
666 | argv = NULL; | 666 | argv = NULL; |
667 | } | 667 | } |
668 | list = do_insert ? list-> m_prev : list-> m_next; | 668 | list = do_insert ? list->m_prev : list->m_next; |
669 | } | 669 | } |
670 | return (show_only) ? 0 : rc; | 670 | return (show_only) ? 0 : rc; |
671 | } | 671 | } |
@@ -674,7 +674,7 @@ static int mod_process ( struct mod_list_t *list, int do_insert ) | |||
674 | * Check the matching between a pattern and a module name. | 674 | * Check the matching between a pattern and a module name. |
675 | * We need this as *_* is equivalent to *-*, even in pattern matching. | 675 | * We need this as *_* is equivalent to *-*, even in pattern matching. |
676 | */ | 676 | */ |
677 | static int check_pattern( const char* pat_src, const char* mod_src ) { | 677 | static int check_pattern(const char* pat_src, const char* mod_src) { |
678 | int ret; | 678 | int ret; |
679 | 679 | ||
680 | if (ENABLE_FEATURE_MODPROBE_FANCY_ALIAS) { | 680 | if (ENABLE_FEATURE_MODPROBE_FANCY_ALIAS) { |
@@ -685,10 +685,10 @@ static int check_pattern( const char* pat_src, const char* mod_src ) { | |||
685 | pat = xstrdup (pat_src); | 685 | pat = xstrdup (pat_src); |
686 | mod = xstrdup (mod_src); | 686 | mod = xstrdup (mod_src); |
687 | 687 | ||
688 | for (p = pat; (p = strchr(p, '-')); *p++ = '_' ); | 688 | for (p = pat; (p = strchr(p, '-')); *p++ = '_'); |
689 | for (p = mod; (p = strchr(p, '-')); *p++ = '_' ); | 689 | for (p = mod; (p = strchr(p, '-')); *p++ = '_'); |
690 | 690 | ||
691 | ret = fnmatch ( pat, mod, 0 ); | 691 | ret = fnmatch(pat, mod, 0); |
692 | 692 | ||
693 | if (ENABLE_FEATURE_CLEAN_UP) { | 693 | if (ENABLE_FEATURE_CLEAN_UP) { |
694 | free (pat); | 694 | free (pat); |
@@ -697,7 +697,7 @@ static int check_pattern( const char* pat_src, const char* mod_src ) { | |||
697 | 697 | ||
698 | return ret; | 698 | return ret; |
699 | } else { | 699 | } else { |
700 | return fnmatch ( pat_src, mod_src, 0 ); | 700 | return fnmatch(pat_src, mod_src, 0); |
701 | } | 701 | } |
702 | } | 702 | } |
703 | 703 | ||
@@ -706,7 +706,7 @@ static int check_pattern( const char* pat_src, const char* mod_src ) { | |||
706 | * head: the highest module in the stack (last to insmod, first to rmmod) | 706 | * head: the highest module in the stack (last to insmod, first to rmmod) |
707 | * tail: the lowest module in the stack (first to insmod, last to rmmod) | 707 | * tail: the lowest module in the stack (first to insmod, last to rmmod) |
708 | */ | 708 | */ |
709 | static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t **tail ) | 709 | static void check_dep(char *mod, struct mod_list_t **head, struct mod_list_t **tail) |
710 | { | 710 | { |
711 | struct mod_list_t *find; | 711 | struct mod_list_t *find; |
712 | struct dep_t *dt; | 712 | struct dep_t *dt; |
@@ -718,122 +718,122 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t * | |||
718 | * so try to match the given module name against such a pattern. | 718 | * so try to match the given module name against such a pattern. |
719 | * Of course if the name in the dependency rule is a plain string, | 719 | * Of course if the name in the dependency rule is a plain string, |
720 | * then we consider it a pattern, and matching will still work. */ | 720 | * then we consider it a pattern, and matching will still work. */ |
721 | for ( dt = depend; dt; dt = dt-> m_next ) { | 721 | for (dt = depend; dt; dt = dt->m_next) { |
722 | if ( check_pattern ( dt-> m_name, mod ) == 0) { | 722 | if (check_pattern(dt->m_name, mod) == 0) { |
723 | break; | 723 | break; |
724 | } | 724 | } |
725 | } | 725 | } |
726 | 726 | ||
727 | if( !dt ) { | 727 | if (!dt) { |
728 | bb_error_msg ("module %s not found", mod); | 728 | bb_error_msg("module %s not found", mod); |
729 | return; | 729 | return; |
730 | } | 730 | } |
731 | 731 | ||
732 | // resolve alias names | 732 | // resolve alias names |
733 | while ( dt-> m_isalias ) { | 733 | while (dt->m_isalias) { |
734 | if ( dt-> m_depcnt == 1 ) { | 734 | if (dt->m_depcnt == 1) { |
735 | struct dep_t *adt; | 735 | struct dep_t *adt; |
736 | 736 | ||
737 | for ( adt = depend; adt; adt = adt-> m_next ) { | 737 | for (adt = depend; adt; adt = adt->m_next) { |
738 | if ( check_pattern ( adt-> m_name, dt-> m_deparr [0] ) == 0 ) | 738 | if (check_pattern(adt->m_name, dt->m_deparr[0]) == 0) |
739 | break; | 739 | break; |
740 | } | 740 | } |
741 | if ( adt ) { | 741 | if (adt) { |
742 | /* This is the module we are aliased to */ | 742 | /* This is the module we are aliased to */ |
743 | struct mod_opt_t *opts = dt-> m_options; | 743 | struct mod_opt_t *opts = dt->m_options; |
744 | /* Option of the alias are appended to the options of the module */ | 744 | /* Option of the alias are appended to the options of the module */ |
745 | while( opts ) { | 745 | while (opts) { |
746 | adt-> m_options = append_option( adt-> m_options, opts-> m_opt_val ); | 746 | adt->m_options = append_option(adt->m_options, opts->m_opt_val); |
747 | opts = opts-> m_next; | 747 | opts = opts->m_next; |
748 | } | 748 | } |
749 | dt = adt; | 749 | dt = adt; |
750 | } | 750 | } |
751 | else { | 751 | else { |
752 | bb_error_msg ("module %s not found", mod); | 752 | bb_error_msg("module %s not found", mod); |
753 | return; | 753 | return; |
754 | } | 754 | } |
755 | } | 755 | } |
756 | else { | 756 | else { |
757 | bb_error_msg ("bad alias %s", dt-> m_name); | 757 | bb_error_msg("bad alias %s", dt->m_name); |
758 | return; | 758 | return; |
759 | } | 759 | } |
760 | } | 760 | } |
761 | 761 | ||
762 | mod = dt-> m_name; | 762 | mod = dt->m_name; |
763 | path = dt-> m_path; | 763 | path = dt->m_path; |
764 | opt = dt-> m_options; | 764 | opt = dt->m_options; |
765 | 765 | ||
766 | // search for duplicates | 766 | // search for duplicates |
767 | for ( find = *head; find; find = find-> m_next ) { | 767 | for (find = *head; find; find = find->m_next) { |
768 | if ( !strcmp ( mod, find-> m_name )) { | 768 | if (!strcmp(mod, find->m_name)) { |
769 | // found -> dequeue it | 769 | // found ->dequeue it |
770 | 770 | ||
771 | if ( find-> m_prev ) | 771 | if (find->m_prev) |
772 | find-> m_prev-> m_next = find-> m_next; | 772 | find->m_prev->m_next = find->m_next; |
773 | else | 773 | else |
774 | *head = find-> m_next; | 774 | *head = find->m_next; |
775 | 775 | ||
776 | if ( find-> m_next ) | 776 | if (find->m_next) |
777 | find-> m_next-> m_prev = find-> m_prev; | 777 | find->m_next->m_prev = find->m_prev; |
778 | else | 778 | else |
779 | *tail = find-> m_prev; | 779 | *tail = find->m_prev; |
780 | 780 | ||
781 | break; // there can be only one duplicate | 781 | break; // there can be only one duplicate |
782 | } | 782 | } |
783 | } | 783 | } |
784 | 784 | ||
785 | if ( !find ) { // did not find a duplicate | 785 | if (!find) { // did not find a duplicate |
786 | find = (struct mod_list_t *) xmalloc ( sizeof(struct mod_list_t)); | 786 | find = xmalloc(sizeof(struct mod_list_t)); |
787 | find-> m_name = mod; | 787 | find->m_name = mod; |
788 | find-> m_path = path; | 788 | find->m_path = path; |
789 | find-> m_options = opt; | 789 | find->m_options = opt; |
790 | } | 790 | } |
791 | 791 | ||
792 | // enqueue at tail | 792 | // enqueue at tail |
793 | if ( *tail ) | 793 | if (*tail) |
794 | (*tail)-> m_next = find; | 794 | (*tail)->m_next = find; |
795 | find-> m_prev = *tail; | 795 | find->m_prev = *tail; |
796 | find-> m_next = 0; | 796 | find->m_next = 0; |
797 | 797 | ||
798 | if ( !*head ) | 798 | if (!*head) |
799 | *head = find; | 799 | *head = find; |
800 | *tail = find; | 800 | *tail = find; |
801 | 801 | ||
802 | if ( dt ) { | 802 | if (dt) { |
803 | int i; | 803 | int i; |
804 | 804 | ||
805 | /* Add all dependable module for that new module */ | 805 | /* Add all dependable module for that new module */ |
806 | for ( i = 0; i < dt-> m_depcnt; i++ ) | 806 | for (i = 0; i < dt->m_depcnt; i++) |
807 | check_dep ( dt-> m_deparr [i], head, tail ); | 807 | check_dep(dt->m_deparr[i], head, tail); |
808 | } | 808 | } |
809 | } | 809 | } |
810 | 810 | ||
811 | static int mod_insert ( char *mod, int argc, char **argv ) | 811 | static int mod_insert(char *mod, int argc, char **argv) |
812 | { | 812 | { |
813 | struct mod_list_t *tail = 0; | 813 | struct mod_list_t *tail = 0; |
814 | struct mod_list_t *head = 0; | 814 | struct mod_list_t *head = 0; |
815 | int rc; | 815 | int rc; |
816 | 816 | ||
817 | // get dep list for module mod | 817 | // get dep list for module mod |
818 | check_dep ( mod, &head, &tail ); | 818 | check_dep(mod, &head, &tail); |
819 | 819 | ||
820 | if ( head && tail ) { | 820 | if (head && tail) { |
821 | if( argc ) { | 821 | if (argc) { |
822 | int i; | 822 | int i; |
823 | // append module args | 823 | // append module args |
824 | for ( i = 0; i < argc; i++ ) | 824 | for (i = 0; i < argc; i++) |
825 | head->m_options = append_option( head->m_options, argv[i] ); | 825 | head->m_options = append_option(head->m_options, argv[i]); |
826 | } | 826 | } |
827 | 827 | ||
828 | // process tail ---> head | 828 | // process tail ---> head |
829 | if ((rc = mod_process ( tail, 1 )) != 0) { | 829 | if ((rc = mod_process(tail, 1)) != 0) { |
830 | /* | 830 | /* |
831 | * In case of using udev, multiple instances of modprobe can be | 831 | * In case of using udev, multiple instances of modprobe can be |
832 | * spawned to load the same module (think of two same usb devices, | 832 | * spawned to load the same module (think of two same usb devices, |
833 | * for example; or cold-plugging at boot time). Thus we shouldn't | 833 | * for example; or cold-plugging at boot time). Thus we shouldn't |
834 | * fail if the module was loaded, and not by us. | 834 | * fail if the module was loaded, and not by us. |
835 | */ | 835 | */ |
836 | if (already_loaded (mod) ) | 836 | if (already_loaded(mod)) |
837 | rc = 0; | 837 | rc = 0; |
838 | } | 838 | } |
839 | } | 839 | } |
@@ -843,7 +843,7 @@ static int mod_insert ( char *mod, int argc, char **argv ) | |||
843 | return rc; | 843 | return rc; |
844 | } | 844 | } |
845 | 845 | ||
846 | static int mod_remove ( char *mod ) | 846 | static int mod_remove(char *mod) |
847 | { | 847 | { |
848 | int rc; | 848 | int rc; |
849 | static struct mod_list_t rm_a_dummy = { "-a", NULL, NULL, NULL, NULL }; | 849 | static struct mod_list_t rm_a_dummy = { "-a", NULL, NULL, NULL, NULL }; |
@@ -851,13 +851,13 @@ static int mod_remove ( char *mod ) | |||
851 | struct mod_list_t *head = 0; | 851 | struct mod_list_t *head = 0; |
852 | struct mod_list_t *tail = 0; | 852 | struct mod_list_t *tail = 0; |
853 | 853 | ||
854 | if ( mod ) | 854 | if (mod) |
855 | check_dep ( mod, &head, &tail ); | 855 | check_dep(mod, &head, &tail); |
856 | else // autoclean | 856 | else // autoclean |
857 | head = tail = &rm_a_dummy; | 857 | head = tail = &rm_a_dummy; |
858 | 858 | ||
859 | if ( head && tail ) | 859 | if (head && tail) |
860 | rc = mod_process ( head, 0 ); // process head ---> tail | 860 | rc = mod_process(head, 0); // process head ---> tail |
861 | else | 861 | else |
862 | rc = 1; | 862 | rc = 1; |
863 | return rc; | 863 | return rc; |
@@ -872,31 +872,31 @@ int modprobe_main(int argc, char** argv) | |||
872 | opt_complementary = "?V-:q-v:v-q"; | 872 | opt_complementary = "?V-:q-v:v-q"; |
873 | main_opts = getopt32(argc, argv, "acdklnqrst:vVC:", | 873 | main_opts = getopt32(argc, argv, "acdklnqrst:vVC:", |
874 | &unused, &unused); | 874 | &unused, &unused); |
875 | if((main_opts & (DUMP_CONF_EXIT | LIST_ALL))) | 875 | if (main_opts & (DUMP_CONF_EXIT | LIST_ALL)) |
876 | return EXIT_SUCCESS; | 876 | return EXIT_SUCCESS; |
877 | if((main_opts & (RESTRICT_DIR | CONFIG_FILE))) | 877 | if (main_opts & (RESTRICT_DIR | CONFIG_FILE)) |
878 | bb_error_msg_and_die("-t and -C not supported"); | 878 | bb_error_msg_and_die("-t and -C not supported"); |
879 | 879 | ||
880 | depend = build_dep ( ); | 880 | depend = build_dep(); |
881 | 881 | ||
882 | if ( !depend ) | 882 | if (!depend) |
883 | bb_error_msg_and_die ( "cannot parse modules.dep" ); | 883 | bb_error_msg_and_die("cannot parse modules.dep"); |
884 | 884 | ||
885 | if (remove_opt) { | 885 | if (remove_opt) { |
886 | do { | 886 | do { |
887 | if (mod_remove ( optind < argc ? | 887 | if (mod_remove(optind < argc ? |
888 | argv [optind] : NULL )) { | 888 | argv[optind] : NULL)) { |
889 | bb_error_msg ("failed to remove module %s", | 889 | bb_error_msg("failed to remove module %s", |
890 | argv [optind] ); | 890 | argv[optind]); |
891 | rc = EXIT_FAILURE; | 891 | rc = EXIT_FAILURE; |
892 | } | 892 | } |
893 | } while ( ++optind < argc ); | 893 | } while (++optind < argc); |
894 | } else { | 894 | } else { |
895 | if (optind >= argc) | 895 | if (optind >= argc) |
896 | bb_error_msg_and_die ( "no module or pattern provided" ); | 896 | bb_error_msg_and_die("no module or pattern provided"); |
897 | 897 | ||
898 | if ( mod_insert ( argv [optind], argc - optind - 1, argv + optind + 1 )) | 898 | if (mod_insert(argv[optind], argc - optind - 1, argv + optind + 1)) |
899 | bb_error_msg_and_die ( "failed to load module %s", argv [optind] ); | 899 | bb_error_msg_and_die("failed to load module %s", argv[optind]); |
900 | } | 900 | } |
901 | 901 | ||
902 | /* Here would be a good place to free up memory allocated during the dependencies build. */ | 902 | /* Here would be a good place to free up memory allocated during the dependencies build. */ |