diff options
author | Elliott Hughes <enh@google.com> | 2019-06-27 14:37:57 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-06-28 11:29:31 -0500 |
commit | 5363b092986416b4ec99716bb2b309856ff22526 (patch) | |
tree | ab2dfc576c1b99500dcd8c1213d76c8d9d8cd592 /toys/other | |
parent | 9b7c46904d340bfaa2ab302cb895c1c2c781cffa (diff) | |
download | toybox-5363b092986416b4ec99716bb2b309856ff22526.tar.gz |
modinfo: various small fixes.
Improve Android support (see code comments).
Remove unnecessary fixed-length limits.
Show error if module not found (plus test).
Expand help text.
Switch to FLAG macro.
Stop hard-coding module assumptions in the tests.
Diffstat (limited to 'toys/other')
-rw-r--r-- | toys/other/modinfo.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/toys/other/modinfo.c b/toys/other/modinfo.c index eaf6cb98..286570f1 100644 --- a/toys/other/modinfo.c +++ b/toys/other/modinfo.c @@ -10,10 +10,14 @@ config MODINFO bool "modinfo" default y help - usage: modinfo [-0] [-b basedir] [-k kernrelease] [-F field] [modulename...] + usage: modinfo [-0] [-b basedir] [-k kernel] [-F field] [module|file...] - Display module fields for all specified modules, looking in - <basedir>/lib/modules/<kernrelease>/ (kernrelease defaults to uname -r). + Display module fields for modules specified by name or .ko path. + + -F Only show the given field + -0 Separate fields with NUL rather than newline + -b Use <basedir> as root for /lib/modules/ + -k Look in given directory under /lib/modules/ */ #define FOR_modinfo @@ -23,6 +27,7 @@ GLOBALS( char *F, *k, *b; long mod; + int count; ) static void output_field(char *field, char *value) @@ -30,7 +35,7 @@ static void output_field(char *field, char *value) if (!TT.F) xprintf("%s:%*c", field, 15-(int)strlen(field), ' '); else if (strcmp(TT.F, field)) return; xprintf("%s", value); - xputc((toys.optflags & FLAG_0) ? 0 : '\n'); + xputc(FLAG(0) ? 0 : '\n'); } static void modinfo_file(char *full_name) @@ -53,6 +58,7 @@ static void modinfo_file(char *full_name) return; } + TT.count++; output_field("filename", full_name); for (pos = buf; pos < buf+len; pos++) { @@ -100,19 +106,30 @@ static int check_module(struct dirtree *new) void modinfo_main(void) { - for(TT.mod = 0; TT.mod<toys.optc; TT.mod++) { + struct utsname uts; + + // Android (as shipped by Google) currently only has modules on /vendor. + // Android does not support multiple sets of modules for different kernels. + if (CFG_TOYBOX_ON_ANDROID) { + if (!TT.b) TT.b = "/vendor"; + if (!TT.k) TT.k = ""; + } else { + uname(&uts); + if (!TT.b) TT.b = ""; + if (!TT.k) TT.k = uts.release; + } + + for (TT.mod = 0; TT.mod<toys.optc; TT.mod++) { char *s = strstr(toys.optargs[TT.mod], ".ko"); if (s && !s[3]) modinfo_file(toys.optargs[TT.mod]); else { - struct utsname uts; - - if (uname(&uts) < 0) perror_exit("bad uname"); - if (snprintf(toybuf, sizeof(toybuf), "%s/lib/modules/%s", - (toys.optflags & FLAG_b) ? TT.b : "", - (toys.optflags & FLAG_k) ? TT.k : uts.release) >= sizeof(toybuf)) - perror_exit("basedir/kernrelease too long"); - dirtree_read(toybuf, check_module); + char *path = xmprintf("%s/lib/modules/%s", TT.b, TT.k); + + TT.count = 0; + dirtree_read(path, check_module); + if (!TT.count) error_msg("%s: not found", toys.optargs[TT.mod]); + free(path); } } } |