diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-08 00:32:49 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-08 00:32:49 +0000 |
commit | 350733abb8157cd8e9e0b6bb10e8699a96c31a20 (patch) | |
tree | 7b7e5b70f47b853478e61082cdcd53a9fdf9ba2e | |
parent | d6bdd5dc088b2673b6e9fd212628a95cc1911756 (diff) | |
download | busybox-w32-350733abb8157cd8e9e0b6bb10e8699a96c31a20.tar.gz busybox-w32-350733abb8157cd8e9e0b6bb10e8699a96c31a20.tar.bz2 busybox-w32-350733abb8157cd8e9e0b6bb10e8699a96c31a20.zip |
Busybox modprobe has a couple of irritating quirks:
- attempting to modprobe a module that is already loaded yields "Failed
to load module", whereas modutils quietly ignores such a request.
- if a module genuinely can't be loaded due to missing symbols or
similar problems, modprobe doesn't produce any useful diagnostics
because the output from insmod has been redirected to /dev/null.
Here's a patch to address these issue
Patch by Philip Blundell
-rw-r--r-- | modutils/modprobe.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index b4bff5100..07cbb6fc7 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
@@ -319,6 +319,32 @@ static struct dep_t *build_dep ( void ) | |||
319 | return first; | 319 | return first; |
320 | } | 320 | } |
321 | 321 | ||
322 | /* return 1 = loaded, 0 = not loaded, -1 = can't tell */ | ||
323 | static int already_loaded (const char *name) | ||
324 | { | ||
325 | int fd; | ||
326 | char buffer[256]; | ||
327 | |||
328 | fd = open ("/proc/modules", O_RDONLY); | ||
329 | if (fd < 0) | ||
330 | return -1; | ||
331 | |||
332 | while ( reads ( fd, buffer, sizeof( buffer ))) { | ||
333 | char *p; | ||
334 | |||
335 | p = strchr (buffer, ' '); | ||
336 | if (p) { | ||
337 | *p = 0; | ||
338 | if (strcmp (name, buffer) == 0) { | ||
339 | close (fd); | ||
340 | return 1; | ||
341 | } | ||
342 | } | ||
343 | } | ||
344 | |||
345 | close (fd); | ||
346 | return 0; | ||
347 | } | ||
322 | 348 | ||
323 | static int mod_process ( struct mod_list_t *list, int do_insert ) | 349 | static int mod_process ( struct mod_list_t *list, int do_insert ) |
324 | { | 350 | { |
@@ -326,10 +352,13 @@ static int mod_process ( struct mod_list_t *list, int do_insert ) | |||
326 | int rc = 1; | 352 | int rc = 1; |
327 | 353 | ||
328 | while ( list ) { | 354 | while ( list ) { |
329 | if ( do_insert ) | 355 | if ( do_insert ) { |
330 | 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 : "" ); | 356 | if (already_loaded (list->m_module) != 1) |
331 | else | 357 | snprintf ( lcmd, sizeof( lcmd ) - 1, "insmod %s %s %s %s %s", do_syslog ? "-s" : "", autoclean ? "-k" : "", quiet ? "-q" : "", list-> m_module, list-> m_options ? list-> m_options : "" ); |
332 | snprintf ( lcmd, sizeof( lcmd ) - 1, "rmmod %s %s 2>/dev/null", do_syslog ? "-s" : "", list-> m_module ); | 358 | } else { |
359 | if (already_loaded (list->m_module) != 0) | ||
360 | snprintf ( lcmd, sizeof( lcmd ) - 1, "rmmod %s %s", do_syslog ? "-s" : "", list-> m_module ); | ||
361 | } | ||
333 | 362 | ||
334 | if ( verbose ) | 363 | if ( verbose ) |
335 | printf ( "%s\n", lcmd ); | 364 | printf ( "%s\n", lcmd ); |