aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerj Kalichev <serj.kalichev@gmail.com>2010-12-26 01:56:19 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-12-26 01:56:19 +0100
commite4e911e7124fca9116ca14c31f125b687d0ae57e (patch)
tree2928eaccd931432fabfbe83e83fa2a9917b4fe2e
parent6088e138e1c6d0b73f8004fc4b4e9ec40430e18e (diff)
downloadbusybox-w32-e4e911e7124fca9116ca14c31f125b687d0ae57e.tar.gz
busybox-w32-e4e911e7124fca9116ca14c31f125b687d0ae57e.tar.bz2
busybox-w32-e4e911e7124fca9116ca14c31f125b687d0ae57e.zip
modprobe: add support for --show-depends
function old new delta modprobe_longopts - 16 +16 packed_usage 28018 28028 +10 modprobe_main 648 653 +5 do_modprobe 580 536 -44 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/1 up/down: 31/-44) Total: -13 bytes Signed-off-by: Serj Kalichev <serj.kalichev@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/tar.c1
-rw-r--r--modutils/modprobe.c95
2 files changed, 60 insertions, 36 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 82caec770..ebaa965c0 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -882,7 +882,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
882 /* Prepend '-' to the first argument if required */ 882 /* Prepend '-' to the first argument if required */
883 opt_complementary = "--:" // first arg is options 883 opt_complementary = "--:" // first arg is options
884 "tt:vv:" // count -t,-v 884 "tt:vv:" // count -t,-v
885 "?:" // bail out with usage instead of error return
886 "X::T::" // cumulative lists 885 "X::T::" // cumulative lists
887#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM 886#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
888 "\xff::" // cumulative lists for --exclude 887 "\xff::" // cumulative lists for --exclude
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index a5cf4babf..8e83f4107 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -72,19 +72,21 @@
72//usage: " from the command line\n" 72//usage: " from the command line\n"
73//usage: 73//usage:
74//usage:#define modprobe_trivial_usage 74//usage:#define modprobe_trivial_usage
75//usage: "[-alrqvs" 75//usage: "[-alrqvs" IF_FEATURE_MODPROBE_BLACKLIST("b") "]"
76//usage: IF_FEATURE_MODPROBE_BLACKLIST("b") 76//usage: IF_LONG_OPTS(" [--show-depends]") " MODULE [symbol=value]..."
77//usage: "] MODULE [symbol=value]..."
78//usage:#define modprobe_full_usage "\n\n" 77//usage:#define modprobe_full_usage "\n\n"
79//usage: "Options:" 78//usage: "Options:"
80//usage: "\n -a Load multiple MODULEs" 79//usage: "\n -a Load multiple MODULEs"
81//usage: "\n -l List (MODULE is a pattern)" 80//usage: "\n -l List (MODULE is a pattern)"
82//usage: "\n -r Remove MODULE (stacks) or do autoclean" 81//usage: "\n -r Remove MODULE (stacks) or do autoclean"
83//usage: "\n -q Quiet" 82//usage: "\n -q Quiet"
84//usage: "\n -v Verbose" 83//usage: "\n -v Verbose"
85//usage: "\n -s Log to syslog" 84//usage: "\n -s Log to syslog"
86//usage: IF_FEATURE_MODPROBE_BLACKLIST( 85//usage: IF_FEATURE_MODPROBE_BLACKLIST(
87//usage: "\n -b Apply blacklist to module names too" 86//usage: "\n -b Apply blacklist to module names too"
87//usage: )
88//usage: IF_LONG_OPTS(
89//usage: "\n --show-depends Show dependencies"
88//usage: ) 90//usage: )
89//usage:#endif /* !ENABLE_MODPROBE_SMALL */ 91//usage:#endif /* !ENABLE_MODPROBE_SMALL */
90 92
@@ -101,24 +103,35 @@
101 * Older versions would only export the direct dependency list. 103 * Older versions would only export the direct dependency list.
102 */ 104 */
103 105
106
104/* Note that usage text doesn't document various 2.4 options 107/* Note that usage text doesn't document various 2.4 options
105 * we pull in through INSMOD_OPTS define */ 108 * we pull in through INSMOD_OPTS define */
106
107#define MODPROBE_COMPLEMENTARY "q-v:v-q:l--ar:a--lr:r--al"
108#define MODPROBE_OPTS "alr" IF_FEATURE_MODPROBE_BLACKLIST("b") 109#define MODPROBE_OPTS "alr" IF_FEATURE_MODPROBE_BLACKLIST("b")
109//#define MODPROBE_COMPLEMENTARY "q-v:v-q:l--acr:a--lr:r--al" 110#undef SD
111#if ENABLE_LONG_OPTS
112static 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"))
110//#define MODPROBE_OPTS "acd:lnrt:C:" IF_FEATURE_MODPROBE_BLACKLIST("b") 120//#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"
111enum { 122enum {
112 MODPROBE_OPT_INSERT_ALL = (INSMOD_OPT_UNUSED << 0), /* a */ 123 OPT_INSERT_ALL = (INSMOD_OPT_UNUSED << 0), /* a */
113 //MODPROBE_OPT_DUMP_ONLY= (INSMOD_OPT_UNUSED << x), /* c */ 124 //OPT_DUMP_ONLY = (INSMOD_OPT_UNUSED << x), /* c */
114 //MODPROBE_OPT_DIRNAME = (INSMOD_OPT_UNUSED << x), /* d */ 125 //OPT_DIRNAME = (INSMOD_OPT_UNUSED << x), /* d */
115 MODPROBE_OPT_LIST_ONLY = (INSMOD_OPT_UNUSED << 1), /* l */ 126 OPT_LIST_ONLY = (INSMOD_OPT_UNUSED << 1), /* l */
116 //MODPROBE_OPT_SHOW_ONLY= (INSMOD_OPT_UNUSED << x), /* n */ 127 //OPT_SHOW_ONLY = (INSMOD_OPT_UNUSED << x), /* n */
117 MODPROBE_OPT_REMOVE = (INSMOD_OPT_UNUSED << 2), /* r */ 128 OPT_REMOVE = (INSMOD_OPT_UNUSED << 2), /* r */
118 //MODPROBE_OPT_RESTRICT = (INSMOD_OPT_UNUSED << x), /* t */ 129 //OPT_RESTRICT = (INSMOD_OPT_UNUSED << x), /* t */
119 //MODPROBE_OPT_VERONLY = (INSMOD_OPT_UNUSED << x), /* V */ 130 //OPT_VERONLY = (INSMOD_OPT_UNUSED << x), /* V */
120 //MODPROBE_OPT_CONFIGFILE=(INSMOD_OPT_UNUSED << x), /* C */ 131 //OPT_CONFIGFILE =(INSMOD_OPT_UNUSED << x), /* C */
121 MODPROBE_OPT_BLACKLIST = (INSMOD_OPT_UNUSED << 3) * ENABLE_FEATURE_MODPROBE_BLACKLIST, 132 OPT_BLACKLIST = (INSMOD_OPT_UNUSED << 3) * ENABLE_FEATURE_MODPROBE_BLACKLIST,
133 OPTBIT_SHOW_DEPS = (3 + ENABLE_FEATURE_MODPROBE_BLACKLIST),
134 OPT_SHOW_DEPS = (INSMOD_OPT_UNUSED << OPTBIT_SHOW_DEPS) * ENABLE_LONG_OPTS,
122}; 135};
123 136
124#define MODULE_FLAG_LOADED 0x0001 137#define MODULE_FLAG_LOADED 0x0001
@@ -145,9 +158,13 @@ struct globals {
145 int num_unresolved_deps; 158 int num_unresolved_deps;
146 /* bool. "Did we have 'symbol:FOO' requested on cmdline?" */ 159 /* bool. "Did we have 'symbol:FOO' requested on cmdline?" */
147 smallint need_symbols; 160 smallint need_symbols;
161 struct utsname uts;
148} FIX_ALIASING; 162} FIX_ALIASING;
149#define G (*(struct globals*)&bb_common_bufsiz1) 163#define G (*(struct globals*)&bb_common_bufsiz1)
150#define INIT_G() do { } while (0) 164#define INIT_G() do { } while (0)
165struct BUG_G_too_big {
166 char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
167};
151 168
152 169
153static int read_config(const char *path); 170static int read_config(const char *path);
@@ -202,7 +219,7 @@ static void add_probe(const char *name)
202 struct module_entry *m; 219 struct module_entry *m;
203 220
204 m = get_or_add_modentry(name); 221 m = get_or_add_modentry(name);
205 if (!(option_mask32 & MODPROBE_OPT_REMOVE) 222 if (!(option_mask32 & (OPT_REMOVE | OPT_SHOW_DEPS))
206 && (m->flags & MODULE_FLAG_LOADED) 223 && (m->flags & MODULE_FLAG_LOADED)
207 ) { 224 ) {
208 DBG("skipping %s, it is already loaded", name); 225 DBG("skipping %s, it is already loaded", name);
@@ -366,7 +383,7 @@ static int do_modprobe(struct module_entry *m)
366 } 383 }
367 DBG("do_modprob'ing %s", m->modname); 384 DBG("do_modprob'ing %s", m->modname);
368 385
369 if (!(option_mask32 & MODPROBE_OPT_REMOVE)) 386 if (!(option_mask32 & OPT_REMOVE))
370 m->deps = llist_rev(m->deps); 387 m->deps = llist_rev(m->deps);
371 388
372 for (l = m->deps; l != NULL; l = l->link) 389 for (l = m->deps; l != NULL; l = l->link)
@@ -379,7 +396,13 @@ static int do_modprobe(struct module_entry *m)
379 fn = llist_pop(&m->deps); /* we leak it */ 396 fn = llist_pop(&m->deps); /* we leak it */
380 m2 = get_or_add_modentry(fn); 397 m2 = get_or_add_modentry(fn);
381 398
382 if (option_mask32 & MODPROBE_OPT_REMOVE) { 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) {
383 /* modprobe -r */ 406 /* modprobe -r */
384 if (m2->flags & MODULE_FLAG_LOADED) { 407 if (m2->flags & MODULE_FLAG_LOADED) {
385 rc = bb_delete_module(m2->modname, O_EXCL); 408 rc = bb_delete_module(m2->modname, O_EXCL);
@@ -456,7 +479,7 @@ static void load_modules_dep(void)
456 479
457 /* Optimization... */ 480 /* Optimization... */
458 if ((m->flags & MODULE_FLAG_LOADED) 481 if ((m->flags & MODULE_FLAG_LOADED)
459 && !(option_mask32 & MODPROBE_OPT_REMOVE) 482 && !(option_mask32 & (OPT_REMOVE | OPT_SHOW_DEPS))
460 ) { 483 ) {
461 DBG("skip deps of %s, it's already loaded", tokens[0]); 484 DBG("skip deps of %s, it's already loaded", tokens[0]);
462 continue; 485 continue;
@@ -477,21 +500,23 @@ static void load_modules_dep(void)
477int modprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 500int modprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
478int modprobe_main(int argc UNUSED_PARAM, char **argv) 501int modprobe_main(int argc UNUSED_PARAM, char **argv)
479{ 502{
480 struct utsname uts;
481 int rc; 503 int rc;
482 unsigned opt; 504 unsigned opt;
483 struct module_entry *me; 505 struct module_entry *me;
484 506
507 INIT_G();
508
509 IF_LONG_OPTS(applet_long_options = modprobe_longopts;)
485 opt_complementary = MODPROBE_COMPLEMENTARY; 510 opt_complementary = MODPROBE_COMPLEMENTARY;
486 opt = getopt32(argv, INSMOD_OPTS MODPROBE_OPTS INSMOD_ARGS); 511 opt = getopt32(argv, INSMOD_OPTS MODPROBE_OPTS INSMOD_ARGS);
487 argv += optind; 512 argv += optind;
488 513
489 /* Goto modules location */ 514 /* Goto modules location */
490 xchdir(CONFIG_DEFAULT_MODULES_DIR); 515 xchdir(CONFIG_DEFAULT_MODULES_DIR);
491 uname(&uts); 516 uname(&G.uts);
492 xchdir(uts.release); 517 xchdir(G.uts.release);
493 518
494 if (opt & MODPROBE_OPT_LIST_ONLY) { 519 if (opt & OPT_LIST_ONLY) {
495 char name[MODULE_NAME_LEN]; 520 char name[MODULE_NAME_LEN];
496 char *colon, *tokens[2]; 521 char *colon, *tokens[2];
497 parser_t *p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read); 522 parser_t *p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read);
@@ -521,7 +546,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
521 logmode = LOGMODE_SYSLOG; 546 logmode = LOGMODE_SYSLOG;
522 547
523 if (!argv[0]) { 548 if (!argv[0]) {
524 if (opt & MODPROBE_OPT_REMOVE) { 549 if (opt & OPT_REMOVE) {
525 /* "modprobe -r" (w/o params). 550 /* "modprobe -r" (w/o params).
526 * "If name is NULL, all unused modules marked 551 * "If name is NULL, all unused modules marked
527 * autoclean will be removed". 552 * autoclean will be removed".
@@ -541,7 +566,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
541 config_close(parser); 566 config_close(parser);
542 } 567 }
543 568
544 if (opt & (MODPROBE_OPT_INSERT_ALL | MODPROBE_OPT_REMOVE)) { 569 if (opt & (OPT_INSERT_ALL | OPT_REMOVE)) {
545 /* Each argument is a module name */ 570 /* Each argument is a module name */
546 do { 571 do {
547 DBG("adding module %s", *argv); 572 DBG("adding module %s", *argv);
@@ -575,7 +600,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
575 /* This is not an alias. Literal names are blacklisted 600 /* This is not an alias. Literal names are blacklisted
576 * only if '-b' is given. 601 * only if '-b' is given.
577 */ 602 */
578 if (!(opt & MODPROBE_OPT_BLACKLIST) 603 if (!(opt & OPT_BLACKLIST)
579 || !(me->flags & MODULE_FLAG_BLACKLISTED) 604 || !(me->flags & MODULE_FLAG_BLACKLISTED)
580 ) { 605 ) {
581 rc |= do_modprobe(me); 606 rc |= do_modprobe(me);
@@ -592,7 +617,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
592 m2 = get_or_add_modentry(realname); 617 m2 = get_or_add_modentry(realname);
593 if (!(m2->flags & MODULE_FLAG_BLACKLISTED) 618 if (!(m2->flags & MODULE_FLAG_BLACKLISTED)
594 && (!(m2->flags & MODULE_FLAG_LOADED) 619 && (!(m2->flags & MODULE_FLAG_LOADED)
595 || (opt & MODPROBE_OPT_REMOVE)) 620 || (opt & (OPT_REMOVE | OPT_SHOW_DEPS)))
596 ) { 621 ) {
597//TODO: we can pass "me" as 2nd param to do_modprobe, 622//TODO: we can pass "me" as 2nd param to do_modprobe,
598//and make do_modprobe emit more meaningful error messages 623//and make do_modprobe emit more meaningful error messages