9 |
*/ |
*/ |
10 |
|
|
11 |
#include "libbb.h" |
#include "libbb.h" |
12 |
|
/* After libbb.h, since it needs sys/types.h on some systems */ |
13 |
#include <sys/utsname.h> /* uname() */ |
#include <sys/utsname.h> /* uname() */ |
14 |
#include <fnmatch.h> |
#include <fnmatch.h> |
15 |
|
|
44 |
char *module_load_options; |
char *module_load_options; |
45 |
smallint dep_bb_seen; |
smallint dep_bb_seen; |
46 |
smallint wrote_dep_bb_ok; |
smallint wrote_dep_bb_ok; |
47 |
int module_count; |
unsigned module_count; |
48 |
int module_found_idx; |
int module_found_idx; |
49 |
int stringbuf_idx; |
unsigned stringbuf_idx; |
50 |
char stringbuf[32 * 1024]; /* some modules have lots of stuff */ |
unsigned stringbuf_size; |
51 |
|
char *stringbuf; /* some modules have lots of stuff */ |
52 |
/* for example, drivers/media/video/saa7134/saa7134.ko */ |
/* for example, drivers/media/video/saa7134/saa7134.ko */ |
53 |
|
/* therefore having a fixed biggish buffer is not wise */ |
54 |
}; |
}; |
55 |
#define G (*ptr_to_globals) |
#define G (*ptr_to_globals) |
56 |
#define modinfo (G.modinfo ) |
#define modinfo (G.modinfo ) |
60 |
#define module_found_idx (G.module_found_idx ) |
#define module_found_idx (G.module_found_idx ) |
61 |
#define module_load_options (G.module_load_options) |
#define module_load_options (G.module_load_options) |
62 |
#define stringbuf_idx (G.stringbuf_idx ) |
#define stringbuf_idx (G.stringbuf_idx ) |
63 |
|
#define stringbuf_size (G.stringbuf_size ) |
64 |
#define stringbuf (G.stringbuf ) |
#define stringbuf (G.stringbuf ) |
65 |
#define INIT_G() do { \ |
#define INIT_G() do { \ |
66 |
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
67 |
} while (0) |
} while (0) |
68 |
|
|
69 |
|
static void append(const char *s) |
70 |
|
{ |
71 |
|
unsigned len = strlen(s); |
72 |
|
if (stringbuf_idx + len + 15 > stringbuf_size) { |
73 |
|
stringbuf_size = stringbuf_idx + len + 127; |
74 |
|
dbg2_error_msg("grow stringbuf to %u", stringbuf_size); |
75 |
|
stringbuf = xrealloc(stringbuf, stringbuf_size); |
76 |
|
} |
77 |
|
memcpy(stringbuf + stringbuf_idx, s, len); |
78 |
|
stringbuf_idx += len; |
79 |
|
} |
80 |
|
|
81 |
static void appendc(char c) |
static void appendc(char c) |
82 |
{ |
{ |
83 |
if (stringbuf_idx < sizeof(stringbuf)) |
/* We appendc() only after append(), + 15 trick in append() |
84 |
stringbuf[stringbuf_idx++] = c; |
* makes it unnecessary to check for overflow here */ |
85 |
|
stringbuf[stringbuf_idx++] = c; |
86 |
} |
} |
87 |
|
|
88 |
static void bksp(void) |
static void bksp(void) |
91 |
stringbuf_idx--; |
stringbuf_idx--; |
92 |
} |
} |
93 |
|
|
|
static void append(const char *s) |
|
|
{ |
|
|
size_t len = strlen(s); |
|
|
if (stringbuf_idx + len < sizeof(stringbuf)) { |
|
|
memcpy(stringbuf + stringbuf_idx, s, len); |
|
|
stringbuf_idx += len; |
|
|
} |
|
|
} |
|
|
|
|
94 |
static void reset_stringbuf(void) |
static void reset_stringbuf(void) |
95 |
{ |
{ |
96 |
stringbuf_idx = 0; |
stringbuf_idx = 0; |
98 |
|
|
99 |
static char* copy_stringbuf(void) |
static char* copy_stringbuf(void) |
100 |
{ |
{ |
101 |
char *copy = xmalloc(stringbuf_idx); |
char *copy = xzalloc(stringbuf_idx + 1); /* terminating NUL */ |
102 |
return memcpy(copy, stringbuf, stringbuf_idx); |
return memcpy(copy, stringbuf, stringbuf_idx); |
103 |
} |
} |
104 |
|
|
222 |
pos = (ptr - module_image); |
pos = (ptr - module_image); |
223 |
} |
} |
224 |
bksp(); /* remove last ' ' */ |
bksp(); /* remove last ' ' */ |
|
appendc('\0'); |
|
225 |
info->aliases = copy_stringbuf(); |
info->aliases = copy_stringbuf(); |
226 |
|
replace(info->aliases, '-', '_'); |
227 |
|
|
228 |
/* "dependency1 depandency2" */ |
/* "dependency1 depandency2" */ |
229 |
reset_stringbuf(); |
reset_stringbuf(); |
234 |
dbg2_error_msg("dep:'%s'", ptr); |
dbg2_error_msg("dep:'%s'", ptr); |
235 |
append(ptr); |
append(ptr); |
236 |
} |
} |
|
appendc('\0'); |
|
237 |
info->deps = copy_stringbuf(); |
info->deps = copy_stringbuf(); |
238 |
|
|
239 |
free(module_image); |
free(module_image); |
319 |
|
|
320 |
while ((line = xmalloc_fgetline(fp)) != NULL) { |
while ((line = xmalloc_fgetline(fp)) != NULL) { |
321 |
char* space; |
char* space; |
322 |
|
char* linebuf; |
323 |
int cur; |
int cur; |
324 |
|
|
325 |
if (!line[0]) { |
if (!line[0]) { |
334 |
if (*space) |
if (*space) |
335 |
*space++ = '\0'; |
*space++ = '\0'; |
336 |
modinfo[cur].aliases = space; |
modinfo[cur].aliases = space; |
337 |
modinfo[cur].deps = xmalloc_fgetline(fp) ? : xzalloc(1); |
linebuf = xmalloc_fgetline(fp); |
338 |
|
modinfo[cur].deps = linebuf ? linebuf : xzalloc(1); |
339 |
if (modinfo[cur].deps[0]) { |
if (modinfo[cur].deps[0]) { |
340 |
/* deps are not "", so next line must be empty */ |
/* deps are not "", so next line must be empty */ |
341 |
line = xmalloc_fgetline(fp); |
line = xmalloc_fgetline(fp); |
384 |
FILE *fp; |
FILE *fp; |
385 |
|
|
386 |
/* We want good error reporting. fdprintf is not good enough. */ |
/* We want good error reporting. fdprintf is not good enough. */ |
387 |
fp = fdopen(fd, "w"); |
fp = xfdopen_for_write(fd); |
|
if (!fp) { |
|
|
close(fd); |
|
|
goto err; |
|
|
} |
|
388 |
i = 0; |
i = 0; |
389 |
while (modinfo[i].pathname) { |
while (modinfo[i].pathname) { |
390 |
fprintf(fp, "%s%s%s\n" "%s%s\n", |
fprintf(fp, "%s%s%s\n" "%s%s\n", |
569 |
info = find_alias(name); |
info = find_alias(name); |
570 |
} |
} |
571 |
|
|
572 |
|
// Problem here: there can be more than one module |
573 |
|
// for the given alias. For example, |
574 |
|
// "pci:v00008086d00007010sv00000000sd00000000bc01sc01i80" matches |
575 |
|
// ata_piix because it has an alias "pci:v00008086d00007010sv*sd*bc*sc*i*" |
576 |
|
// and ata_generic, it has an alias "alias=pci:v*d*sv*sd*bc01sc01i*" |
577 |
|
// Standard modprobe would load them both. |
578 |
|
// In this code, find_alias() returns only the first matching module. |
579 |
|
|
580 |
/* rmmod? unload it by name */ |
/* rmmod? unload it by name */ |
581 |
if (is_rmmod) { |
if (is_rmmod) { |
582 |
if (delete_module(name, O_NONBLOCK | O_EXCL) != 0 |
if (delete_module(name, O_NONBLOCK | O_EXCL) != 0 |
667 |
[-b basedirectory] [forced_version] |
[-b basedirectory] [forced_version] |
668 |
depmod [-n -e -v -q -r -u] [-F kernelsyms] module1.ko module2.ko ... |
depmod [-n -e -v -q -r -u] [-F kernelsyms] module1.ko module2.ko ... |
669 |
If no arguments (except options) are given, "depmod -a" is assumed. |
If no arguments (except options) are given, "depmod -a" is assumed. |
670 |
depmod will output a dependancy list suitable for the modprobe utility. |
depmod will output a dependency list suitable for the modprobe utility. |
671 |
Options: |
Options: |
672 |
-a, --all Probe all modules |
-a, --all Probe all modules |
673 |
-A, --quick Only does the work if there's a new module |
-A, --quick Only does the work if there's a new module |
690 |
{ |
{ |
691 |
struct utsname uts; |
struct utsname uts; |
692 |
char applet0 = applet_name[0]; |
char applet0 = applet_name[0]; |
693 |
USE_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(char *options;) |
IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(char *options;) |
694 |
|
|
695 |
/* are we lsmod? -> just dump /proc/modules */ |
/* are we lsmod? -> just dump /proc/modules */ |
696 |
if ('l' == applet0) { |
if ('l' == applet0) { |
784 |
len = MAXINT(ssize_t); |
len = MAXINT(ssize_t); |
785 |
map = xmalloc_xopen_read_close(*argv, &len); |
map = xmalloc_xopen_read_close(*argv, &len); |
786 |
if (init_module(map, len, |
if (init_module(map, len, |
787 |
USE_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(options ? options : "") |
IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(options ? options : "") |
788 |
SKIP_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE("") |
IF_NOT_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE("") |
789 |
) != 0) |
) != 0) |
790 |
bb_error_msg_and_die("cannot insert '%s': %s", |
bb_error_msg_and_die("can't insert '%s': %s", |
791 |
*argv, moderror(errno)); |
*argv, moderror(errno)); |
792 |
return 0; |
return 0; |
793 |
} |
} |
802 |
} while (*argv); |
} while (*argv); |
803 |
|
|
804 |
if (ENABLE_FEATURE_CLEAN_UP) { |
if (ENABLE_FEATURE_CLEAN_UP) { |
805 |
USE_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(free(options);) |
IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(free(options);) |
806 |
} |
} |
807 |
return EXIT_SUCCESS; |
return EXIT_SUCCESS; |
808 |
} |
} |