From: Emil Velikov Date: Mon, 19 May 2025 20:08:26 +0000 (+0100) Subject: tools/modprobe: accept module name with --show-exports X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5dfa7c9a9bdad68df1c3bb1a366d6a8cd5d13f3b;p=thirdparty%2Fkmod.git tools/modprobe: accept module name with --show-exports Use the newly introduced helper module_new_from_any(), so we accept both files as well as modules. This means you can now do: - modprobe --show-exports drm-vram-helper, alongside the existing - modprobe --show-exports /full/path/to/the/module/drm_vram_helper.ko Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/353 Signed-off-by: Lucas De Marchi --- diff --git a/tools/modprobe.c b/tools/modprobe.c index 54a71d6a..b4e4acaf 100644 --- a/tools/modprobe.c +++ b/tools/modprobe.c @@ -248,20 +248,13 @@ static int show_modversions(struct kmod_ctx *ctx, const char *filename) return 0; } -static int show_exports(struct kmod_ctx *ctx, const char *filename) +static int print_exports(const struct kmod_module *mod) { struct kmod_list *l, *list = NULL; - struct kmod_module *mod; - int err = kmod_module_new_from_path(ctx, filename, &mod); + int err = kmod_module_get_symbols(mod, &list); if (err < 0) { - LOG("Module %s not found.\n", filename); - return err; - } - - err = kmod_module_get_symbols(mod, &list); - if (err < 0) { - LOG("could not get symbols of %s: %s\n", filename, strerror(-err)); - kmod_module_unref(mod); + LOG("could not get symbols of %s: %s\n", kmod_module_get_name(mod), + strerror(-err)); return err; } @@ -271,10 +264,32 @@ static int show_exports(struct kmod_ctx *ctx, const char *filename) printf("0x%08" PRIx64 "\t%s\n", crc, symbol); } kmod_module_symbols_free_list(list); - kmod_module_unref(mod); return 0; } +static int show_exports(struct kmod_ctx *ctx, const char *filename) +{ + struct kmod_list *l, *list = NULL; + struct kmod_module *mod = NULL; + int err = module_new_from_any(ctx, filename, &mod, &list); + if (err < 0) + return err; + + /* If module is loaded from path */ + if (mod != NULL) { + err = print_exports(mod); + kmod_module_unref(mod); + } else { + kmod_list_foreach(l, list) { + mod = kmod_module_get_module(l); + err = print_exports(mod); + kmod_module_unref(mod); + } + kmod_module_unref_list(list); + } + return err; +} + static int command_do(struct kmod_module *module, const char *type, const char *command, const char *cmdline_opts) {