aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toys/other/modinfo.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/toys/other/modinfo.c b/toys/other/modinfo.c
index 3548247d..33140370 100644
--- a/toys/other/modinfo.c
+++ b/toys/other/modinfo.c
@@ -2,13 +2,15 @@
*
* Copyright 2012 Andre Renaud <andre@bluewatersys.com>
-USE_MODINFO(NEWTOY(modinfo, "<1F:0", TOYFLAG_BIN))
+USE_MODINFO(NEWTOY(modinfo, "<1b:k:F:0", TOYFLAG_BIN))
config MODINFO
bool "modinfo"
default y
help
- usage: modinfo [-0] [-F field] [modulename...]
+ usage: modinfo [-0] [-b basedir] [-k kernrelease] [-F field] [modulename...]
+ Display module fields for all specified modules, looking in
+ <basedir>/lib/modules/<kernrelease>/ (kernrelease defaults to uname -r).
*/
#define FOR_modinfo
@@ -16,6 +18,8 @@ config MODINFO
GLOBALS(
char *field;
+ char *knam;
+ char *base;
long mod;
)
@@ -23,7 +27,7 @@ GLOBALS(
static void output_field(char *field, char *value)
{
if (!TT.field) xprintf("%s:%*c", field, 15 - strlen(field), ' ');
- else if (!strcmp(TT.field, field)) return;
+ else if (strcmp(TT.field, field)) return;
xprintf("%s", value);
xputc((toys.optflags & FLAG_0) ? 0 : '\n');
}
@@ -100,7 +104,10 @@ void modinfo_main(void)
struct utsname uts;
if (uname(&uts) < 0) perror_exit("bad uname");
- sprintf(toybuf, "/lib/modules/%s", uts.release);
+ if (snprintf(toybuf, sizeof(toybuf), "%s/lib/modules/%s",
+ (toys.optflags & FLAG_b) ? TT.base : "",
+ (toys.optflags & FLAG_k) ? TT.knam : uts.release) >= sizeof(toybuf))
+ perror_exit("basedir/kernrelease too long");
dirtree_read(toybuf, check_module);
}
}