From: Dan McGee Date: Sat, 4 Feb 2012 02:25:00 +0000 (-0600) Subject: modinfo: handle arguments more carefully X-Git-Tag: v5~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a23f0c9c55f46635cb58e5269b19b9e4471b5150;p=thirdparty%2Fkmod.git modinfo: handle arguments more carefully A simple case of breakage before this commit: $ touch aes $ modinfo aes filename: /tmp/aes ERROR: could not get modinfo from 'aes': Invalid argument Add a new is_module_filename() function that attempts to do more than just check if the passed argument is a regular file. We look at the name for a '.ko' string, and if that is found, ensure it is either at the end of the string or followed by another '.' (for .gz and .xz modules, for instance). We don't make this second option conditional on the way the tools are built with compression support; the file is a module file regardless and should always be treated that way. When doing this, and noticed in the test suite output, we open the system modules index unconditionally, even if it is never going to be used during the modinfo call, which is the case when passing module filenames directly. For only one module there's not much advantage in pre-loading the index, so just remove the call to kmod_load_resources(). With-help-from: Dave Reisner [lucas.demarchi@profusion.mobi: remove call to kmod_load_resources()] --- diff --git a/tools/kmod-modinfo.c b/tools/kmod-modinfo.c index 87483a59..bf897f43 100644 --- a/tools/kmod-modinfo.c +++ b/tools/kmod-modinfo.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -332,6 +333,24 @@ static void help(const char *progname) progname); } +static bool is_module_filename(const char *name) +{ + struct stat st; + const char *ptr; + + if (stat(name, &st) == 0 && S_ISREG(st.st_mode) && + (ptr = strstr(name, ".ko")) != NULL) { + /* + * We screened for .ko; make sure this is either at the end of + * the name or followed by another '.' (e.g. gz or xz modules) + */ + if(ptr[3] == '\0' || ptr[3] == '.') + return true; + } + + return false; +} + static int do_modinfo(int argc, char *argv[]) { struct kmod_ctx *ctx; @@ -418,15 +437,13 @@ static int do_modinfo(int argc, char *argv[]) fputs("Error: kmod_new() failed!\n", stderr); return EXIT_FAILURE; } - kmod_load_resources(ctx); err = 0; for (i = optind; i < argc; i++) { const char *name = argv[i]; - struct stat st; int r; - if (stat(name, &st) == 0 && S_ISREG(st.st_mode)) + if (is_module_filename(name)) r = modinfo_path_do(ctx, name); else r = modinfo_alias_do(ctx, name);