aboutsummaryrefslogtreecommitdiff
path: root/toys/other
diff options
context:
space:
mode:
authorIsaac Dunham <idunham@lavabit.com>2013-06-28 02:11:48 -0500
committerIsaac Dunham <idunham@lavabit.com>2013-06-28 02:11:48 -0500
commit7bb5221b1f943c53c9abb96f7a25ef922ae9972d (patch)
tree1fef4c7a7f032d1ff0a486003c9b7dccf79e05c1 /toys/other
parentaafa148d9d2c0dd59abed1a4e3715d1e9dee318c (diff)
downloadtoybox-7bb5221b1f943c53c9abb96f7a25ef922ae9972d.tar.gz
modinfo: support -b basedir and -k kernel.release, fix two bugs
Add two less-frequently used flags for modinfo; -b specifies an alternate root and -k replaces the output of uname -r. Additionally, avoid a potential overflow in sprintf, and correct an inverted test.
Diffstat (limited to 'toys/other')
-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);
}
}