diff options
author | Serj Kalichev <serj.kalichev@gmail.com> | 2010-12-28 04:18:18 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-12-28 04:18:18 +0100 |
commit | 8578196b763a70746f2ab17170eb7ca9399ab8ac (patch) | |
tree | f987c5a2a29280c1390a6dad8d55813d053bb96e | |
parent | 260fb551ff4ba0cb8a5fdff848bce10588611231 (diff) | |
download | busybox-w32-8578196b763a70746f2ab17170eb7ca9399ab8ac.tar.gz busybox-w32-8578196b763a70746f2ab17170eb7ca9399ab8ac.tar.bz2 busybox-w32-8578196b763a70746f2ab17170eb7ca9399ab8ac.zip |
modprobe: add -D option (synonym of --show-depends)
The modern module-init-tools 3.12 has "-D" option and it works.
The --show-depends and -a options can be used together due to upstream modprobe
behaviour.
function old new delta
do_modprobe 536 579 +43
packed_usage 28035 28042 +7
modprobe_main 653 657 +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 54/0) Total: 54 bytes
Signed-off-by: Serj Kalichev <serj.kalichev@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | modutils/modprobe.c | 121 |
1 files changed, 67 insertions, 54 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 8e83f4107..73df39c6c 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
@@ -10,6 +10,20 @@ | |||
10 | 10 | ||
11 | //applet:IF_MODPROBE(APPLET(modprobe, _BB_DIR_SBIN, _BB_SUID_DROP)) | 11 | //applet:IF_MODPROBE(APPLET(modprobe, _BB_DIR_SBIN, _BB_SUID_DROP)) |
12 | 12 | ||
13 | #include "libbb.h" | ||
14 | #include "modutils.h" | ||
15 | #include <sys/utsname.h> | ||
16 | #include <fnmatch.h> | ||
17 | |||
18 | //#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__) | ||
19 | #define DBG(...) ((void)0) | ||
20 | |||
21 | /* Note that unlike older versions of modules.dep/depmod (busybox and m-i-t), | ||
22 | * we expect the full dependency list to be specified in modules.dep. | ||
23 | * Older versions would only export the direct dependency list. | ||
24 | */ | ||
25 | |||
26 | |||
13 | //usage:#if !ENABLE_MODPROBE_SMALL | 27 | //usage:#if !ENABLE_MODPROBE_SMALL |
14 | //usage:#define modprobe_notes_usage | 28 | //usage:#define modprobe_notes_usage |
15 | //usage: "modprobe can (un)load a stack of modules, passing each module options (when\n" | 29 | //usage: "modprobe can (un)load a stack of modules, passing each module options (when\n" |
@@ -72,51 +86,27 @@ | |||
72 | //usage: " from the command line\n" | 86 | //usage: " from the command line\n" |
73 | //usage: | 87 | //usage: |
74 | //usage:#define modprobe_trivial_usage | 88 | //usage:#define modprobe_trivial_usage |
75 | //usage: "[-alrqvs" IF_FEATURE_MODPROBE_BLACKLIST("b") "]" | 89 | //usage: "[-alrqvsD" IF_FEATURE_MODPROBE_BLACKLIST("b") "]" |
76 | //usage: IF_LONG_OPTS(" [--show-depends]") " MODULE [symbol=value]..." | 90 | //usage: " MODULE [symbol=value]..." |
77 | //usage:#define modprobe_full_usage "\n\n" | 91 | //usage:#define modprobe_full_usage "\n\n" |
78 | //usage: "Options:" | 92 | //usage: "Options:" |
79 | //usage: "\n -a Load multiple MODULEs" | 93 | //usage: "\n -a Load multiple MODULEs" |
80 | //usage: "\n -l List (MODULE is a pattern)" | 94 | //usage: "\n -l List (MODULE is a pattern)" |
81 | //usage: "\n -r Remove MODULE (stacks) or do autoclean" | 95 | //usage: "\n -r Remove MODULE (stacks) or do autoclean" |
82 | //usage: "\n -q Quiet" | 96 | //usage: "\n -q Quiet" |
83 | //usage: "\n -v Verbose" | 97 | //usage: "\n -v Verbose" |
84 | //usage: "\n -s Log to syslog" | 98 | //usage: "\n -s Log to syslog" |
99 | //usage: "\n -D Show dependencies" | ||
85 | //usage: IF_FEATURE_MODPROBE_BLACKLIST( | 100 | //usage: IF_FEATURE_MODPROBE_BLACKLIST( |
86 | //usage: "\n -b Apply blacklist to module names too" | 101 | //usage: "\n -b Apply blacklist to module names too" |
87 | //usage: ) | ||
88 | //usage: IF_LONG_OPTS( | ||
89 | //usage: "\n --show-depends Show dependencies" | ||
90 | //usage: ) | 102 | //usage: ) |
91 | //usage:#endif /* !ENABLE_MODPROBE_SMALL */ | 103 | //usage:#endif /* !ENABLE_MODPROBE_SMALL */ |
92 | 104 | ||
93 | #include "libbb.h" | ||
94 | #include "modutils.h" | ||
95 | #include <sys/utsname.h> | ||
96 | #include <fnmatch.h> | ||
97 | |||
98 | //#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__) | ||
99 | #define DBG(...) ((void)0) | ||
100 | |||
101 | /* Note that unlike older versions of modules.dep/depmod (busybox and m-i-t), | ||
102 | * we expect the full dependency list to be specified in modules.dep. | ||
103 | * Older versions would only export the direct dependency list. | ||
104 | */ | ||
105 | |||
106 | |||
107 | /* Note that usage text doesn't document various 2.4 options | 105 | /* Note that usage text doesn't document various 2.4 options |
108 | * we pull in through INSMOD_OPTS define */ | 106 | * we pull in through INSMOD_OPTS define */ |
109 | #define MODPROBE_OPTS "alr" IF_FEATURE_MODPROBE_BLACKLIST("b") | 107 | #define MODPROBE_OPTS "alrD" IF_FEATURE_MODPROBE_BLACKLIST("b") |
110 | #undef SD | 108 | /* -a and -D _are_ in fact compatible */ |
111 | #if ENABLE_LONG_OPTS | 109 | #define MODPROBE_COMPLEMENTARY ("q-v:v-q:l--arD:r--alD:a--lr:D--rl") |
112 | static const char modprobe_longopts[] ALIGN1 = | ||
113 | "show-depends\0" No_argument "\xff" | ||
114 | ; | ||
115 | # define SD "\xff" | ||
116 | #else | ||
117 | # define SD "" | ||
118 | #endif | ||
119 | #define MODPROBE_COMPLEMENTARY ("q-v:v-q:l--ar"SD":a--lr"SD":r--al"SD IF_LONG_OPTS(":\xff--arl")) | ||
120 | //#define MODPROBE_OPTS "acd:lnrt:C:" IF_FEATURE_MODPROBE_BLACKLIST("b") | 110 | //#define MODPROBE_OPTS "acd:lnrt:C:" IF_FEATURE_MODPROBE_BLACKLIST("b") |
121 | //#define MODPROBE_COMPLEMENTARY "q-v:v-q:l--acr:a--lr:r--al" | 111 | //#define MODPROBE_COMPLEMENTARY "q-v:v-q:l--acr:a--lr:r--al" |
122 | enum { | 112 | enum { |
@@ -128,11 +118,28 @@ enum { | |||
128 | OPT_REMOVE = (INSMOD_OPT_UNUSED << 2), /* r */ | 118 | OPT_REMOVE = (INSMOD_OPT_UNUSED << 2), /* r */ |
129 | //OPT_RESTRICT = (INSMOD_OPT_UNUSED << x), /* t */ | 119 | //OPT_RESTRICT = (INSMOD_OPT_UNUSED << x), /* t */ |
130 | //OPT_VERONLY = (INSMOD_OPT_UNUSED << x), /* V */ | 120 | //OPT_VERONLY = (INSMOD_OPT_UNUSED << x), /* V */ |
131 | //OPT_CONFIGFILE =(INSMOD_OPT_UNUSED << x), /* C */ | 121 | //OPT_CONFIGFILE = (INSMOD_OPT_UNUSED << x), /* C */ |
132 | OPT_BLACKLIST = (INSMOD_OPT_UNUSED << 3) * ENABLE_FEATURE_MODPROBE_BLACKLIST, | 122 | OPT_SHOW_DEPS = (INSMOD_OPT_UNUSED << 3), /* D */ |
133 | OPTBIT_SHOW_DEPS = (3 + ENABLE_FEATURE_MODPROBE_BLACKLIST), | 123 | OPT_BLACKLIST = (INSMOD_OPT_UNUSED << 4) * ENABLE_FEATURE_MODPROBE_BLACKLIST, |
134 | OPT_SHOW_DEPS = (INSMOD_OPT_UNUSED << OPTBIT_SHOW_DEPS) * ENABLE_LONG_OPTS, | ||
135 | }; | 124 | }; |
125 | #if ENABLE_LONG_OPTS | ||
126 | static const char modprobe_longopts[] ALIGN1 = | ||
127 | /* nobody asked for long opts (yet) */ | ||
128 | // "all\0" No_argument "a" | ||
129 | // "list\0" No_argument "l" | ||
130 | // "remove\0" No_argument "r" | ||
131 | // "quiet\0" No_argument "q" | ||
132 | // "verbose\0" No_argument "v" | ||
133 | // "syslog\0" No_argument "s" | ||
134 | /* module-init-tools 3.11.1 has only long opt --show-depends | ||
135 | * but no short -D, we provide long opt for scripts which | ||
136 | * were written for 3.11.1: */ | ||
137 | "show-depends\0" No_argument "D" | ||
138 | // IF_FEATURE_MODPROBE_BLACKLIST( | ||
139 | // "use-blacklist\0" No_argument "b" | ||
140 | // ) | ||
141 | ; | ||
142 | #endif | ||
136 | 143 | ||
137 | #define MODULE_FLAG_LOADED 0x0001 | 144 | #define MODULE_FLAG_LOADED 0x0001 |
138 | #define MODULE_FLAG_NEED_DEPS 0x0002 | 145 | #define MODULE_FLAG_NEED_DEPS 0x0002 |
@@ -370,8 +377,6 @@ static char *parse_and_add_kcmdline_module_options(char *options, const char *mo | |||
370 | */ | 377 | */ |
371 | static int do_modprobe(struct module_entry *m) | 378 | static int do_modprobe(struct module_entry *m) |
372 | { | 379 | { |
373 | struct module_entry *m2 = m2; /* for compiler */ | ||
374 | char *fn, *options; | ||
375 | int rc, first; | 380 | int rc, first; |
376 | llist_t *l; | 381 | llist_t *l; |
377 | 382 | ||
@@ -392,16 +397,13 @@ static int do_modprobe(struct module_entry *m) | |||
392 | first = 1; | 397 | first = 1; |
393 | rc = 0; | 398 | rc = 0; |
394 | while (m->deps) { | 399 | while (m->deps) { |
400 | struct module_entry *m2; | ||
401 | char *fn, *options; | ||
402 | |||
395 | rc = 0; | 403 | rc = 0; |
396 | fn = llist_pop(&m->deps); /* we leak it */ | 404 | fn = llist_pop(&m->deps); /* we leak it */ |
397 | m2 = get_or_add_modentry(fn); | 405 | m2 = get_or_add_modentry(fn); |
398 | 406 | ||
399 | if (option_mask32 & OPT_SHOW_DEPS) { | ||
400 | printf("insmod %s/%s/%s\n", CONFIG_DEFAULT_MODULES_DIR, | ||
401 | G.uts.release, fn); | ||
402 | continue; | ||
403 | } | ||
404 | |||
405 | if (option_mask32 & OPT_REMOVE) { | 407 | if (option_mask32 & OPT_REMOVE) { |
406 | /* modprobe -r */ | 408 | /* modprobe -r */ |
407 | if (m2->flags & MODULE_FLAG_LOADED) { | 409 | if (m2->flags & MODULE_FLAG_LOADED) { |
@@ -422,16 +424,27 @@ static int do_modprobe(struct module_entry *m) | |||
422 | continue; | 424 | continue; |
423 | } | 425 | } |
424 | 426 | ||
425 | if (m2->flags & MODULE_FLAG_LOADED) { | ||
426 | DBG("%s is already loaded, skipping", fn); | ||
427 | continue; | ||
428 | } | ||
429 | |||
430 | options = m2->options; | 427 | options = m2->options; |
431 | m2->options = NULL; | 428 | m2->options = NULL; |
432 | options = parse_and_add_kcmdline_module_options(options, m2->modname); | 429 | options = parse_and_add_kcmdline_module_options(options, m2->modname); |
433 | if (m == m2) | 430 | if (m == m2) |
434 | options = gather_options_str(options, G.cmdline_mopts); | 431 | options = gather_options_str(options, G.cmdline_mopts); |
432 | |||
433 | if (option_mask32 & OPT_SHOW_DEPS) { | ||
434 | printf(options ? "insmod %s/%s/%s %s\n" | ||
435 | : "insmod %s/%s/%s\n", | ||
436 | CONFIG_DEFAULT_MODULES_DIR, G.uts.release, fn, | ||
437 | options); | ||
438 | free(options); | ||
439 | continue; | ||
440 | } | ||
441 | |||
442 | if (m2->flags & MODULE_FLAG_LOADED) { | ||
443 | DBG("%s is already loaded, skipping", fn); | ||
444 | free(options); | ||
445 | continue; | ||
446 | } | ||
447 | |||
435 | rc = bb_init_module(fn, options); | 448 | rc = bb_init_module(fn, options); |
436 | DBG("loaded %s '%s', rc:%d", fn, options, rc); | 449 | DBG("loaded %s '%s', rc:%d", fn, options, rc); |
437 | if (rc == EEXIST) | 450 | if (rc == EEXIST) |