From dd4d2299b724039519f58663e5a3cab7aa735149 Mon Sep 17 00:00:00 2001 From: Alexey Gladkov Date: Mon, 28 Mar 2022 13:26:00 +0200 Subject: initrd-scanmod: Add verbose option Signed-off-by: Alexey Gladkov --- utils/initrd-scanmod/initrd-scanmod-walk.c | 39 +++++++++++++++++++--- utils/initrd-scanmod/initrd-scanmod.c | 12 ++++++- utils/initrd-scanmod/initrd-scanmod.h | 2 ++ 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/utils/initrd-scanmod/initrd-scanmod-walk.c b/utils/initrd-scanmod/initrd-scanmod-walk.c index 655a72b5e..87352b718 100644 --- a/utils/initrd-scanmod/initrd-scanmod-walk.c +++ b/utils/initrd-scanmod/initrd-scanmod-walk.c @@ -108,13 +108,23 @@ process_module_ruleset(struct kmod_ctx *ctx, const char *filename, struct rulese if (!(modname = kmod_module_get_name(mod))) goto exit; + if (verbose > 1) + warnx("%s: checking module against the ruleset patterns from %s ...", kmod_module_get_path(mod), set->filename); + if (set->flags & RULESET_HAS_PATHS) { rc = match_filename(kmod_module_get_path(mod), set->paths); if (rc < 0) goto exit; - if (rc > 0) + if (rc > 0) { is_match = 1; + + if (verbose > 1) + warnx("%s: path matches", kmod_module_get_path(mod)); + } else { + if (verbose > 1) + warnx("%s: path does not match", kmod_module_get_path(mod)); + } } if (set->flags & RULESET_HAS_INFO) { @@ -128,9 +138,16 @@ process_module_ruleset(struct kmod_ctx *ctx, const char *filename, struct rulese if (rc < 0) goto exit; - if (rc > 0) + if (rc > 0) { is_match = 1; + if (verbose > 1) + warnx("%s: the module information matches", kmod_module_get_path(mod)); + } else { + if (verbose > 1) + warnx("%s: the module information does not match", kmod_module_get_path(mod)); + } + } else if (rc < 0) { errno = -rc; warn("Could not get information from '%s'", modname); @@ -149,9 +166,16 @@ process_module_ruleset(struct kmod_ctx *ctx, const char *filename, struct rulese if (rc < 0) goto exit; - if (rc > 0) + if (rc > 0) { is_match = 1; + if (verbose > 1) + warnx("%s: symbols matches", kmod_module_get_path(mod)); + } else { + if (verbose > 1) + warnx("%s: symbols does not match", kmod_module_get_path(mod)); + } + } else if (rc < 0 && rc != -ENOENT) { errno = -rc; warn("Could not get symbols from '%s'", modname); @@ -168,9 +192,16 @@ process_module_ruleset(struct kmod_ctx *ctx, const char *filename, struct rulese if (rc < 0) goto exit; - if (rc > 0) + if (rc > 0) { is_match = 1; + if (verbose > 1) + warnx("%s: symbols matches", kmod_module_get_path(mod)); + } else { + if (verbose > 1) + warnx("%s: symbols does not match", kmod_module_get_path(mod)); + } + } else if (rc < 0 && rc != -ENOENT) { errno = -rc; warn("Could not get dependency symbols from '%s'", modname); diff --git a/utils/initrd-scanmod/initrd-scanmod.c b/utils/initrd-scanmod/initrd-scanmod.c index 90e6718b7..4f5cfcd1a 100644 --- a/utils/initrd-scanmod/initrd-scanmod.c +++ b/utils/initrd-scanmod/initrd-scanmod.c @@ -12,11 +12,14 @@ #include "initrd-scanmod.h" #include "config.h" -const char short_opts[] = "Vhb:k:"; +int verbose = 0; + +const char short_opts[] = "Vhb:k:v"; const struct option long_opts[] = { { "set-version", required_argument, 0, 'k' }, { "base-dir", required_argument, 0, 'b' }, { "help", no_argument, NULL, 'h' }, + { "verbose", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } }; @@ -30,6 +33,7 @@ usage(const char *progname, int code) "Options:\n" " -k, --set-version=VERSION use VERSION instead of `uname -r`;\n" " -b, --base-dir=DIR use DIR as filesystem root for /lib/modules;\n" + " -v, --verbose print a message for each action;\n" " -h, --help display this help and exit;\n" " -V, --version output version information and exit.\n" "\n" @@ -68,6 +72,9 @@ main(int argc, char **argv) case 'b': basedir = optarg; break; + case 'v': + verbose++; + break; case 'h': usage(basename(argv[0]), EXIT_SUCCESS); break; @@ -95,6 +102,9 @@ main(int argc, char **argv) xasprintf(&kerneldir, "%s/lib/modules/%s", basedir, kversion); + if (verbose) + warnx("kernel directory: %s", kerneldir); + parse_rules(argc - optind, argv + optind); find_modules(kerneldir); diff --git a/utils/initrd-scanmod/initrd-scanmod.h b/utils/initrd-scanmod/initrd-scanmod.h index 4f4ee07e8..f1ca48ca2 100644 --- a/utils/initrd-scanmod/initrd-scanmod.h +++ b/utils/initrd-scanmod/initrd-scanmod.h @@ -4,6 +4,8 @@ #include #include +extern int verbose; + // findmodule-common.c void *xmalloc(size_t size); void *xrealloc(void *ptr, size_t nmemb, size_t elem_size); -- 2.33.0