From: Gustavo Sousa Date: Fri, 13 Jan 2023 21:37:44 +0000 (-0300) Subject: modprobe: Move insertion block into separate function X-Git-Tag: v31~25 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fkmod.git;a=commitdiff_plain;h=f3db15e9009777318da6ade7cc82b7dfb472d0c4 modprobe: Move insertion block into separate function That same logic will be used for enabling modprobe for paths in the next patch. As such, prepare for that by extracting that block into its own function. Signed-off-by: Gustavo Sousa Signed-off-by: Lucas De Marchi --- diff --git a/tools/modprobe.c b/tools/modprobe.c index 3240c2b..d4012fa 100644 --- a/tools/modprobe.c +++ b/tools/modprobe.c @@ -569,15 +569,53 @@ static void print_action(struct kmod_module *m, bool install, printf("insmod %s %s\n", kmod_module_get_path(m), options); } +static int insmod_insert(struct kmod_module *mod, int flags, + const char *extra_options) +{ + int err = 0; + void (*show)(struct kmod_module *m, bool install, + const char *options) = NULL; + + if (do_show || verbose > DEFAULT_VERBOSE) + show = &print_action; + + if (lookup_only) + printf("%s\n", kmod_module_get_name(mod)); + else + err = kmod_module_probe_insert_module(mod, flags, + extra_options, NULL, NULL, show); + + if (err >= 0) + /* ignore flag return values such as a mod being blacklisted */ + err = 0; + else { + switch (err) { + case -EEXIST: + ERR("could not insert '%s': Module already in kernel\n", + kmod_module_get_name(mod)); + break; + case -ENOENT: + ERR("could not insert '%s': Unknown symbol in module, " + "or unknown parameter (see dmesg)\n", + kmod_module_get_name(mod)); + break; + default: + ERR("could not insert '%s': %s\n", + kmod_module_get_name(mod), + strerror(-err)); + break; + } + } + + return err; +} + static int insmod(struct kmod_ctx *ctx, const char *alias, const char *extra_options) { struct kmod_list *l, *list = NULL; int err, flags = 0; - void (*show)(struct kmod_module *m, bool install, - const char *options) = NULL; - err = kmod_module_new_from_lookup(ctx, alias, &list); if (list == NULL || err < 0) { @@ -596,8 +634,6 @@ static int insmod(struct kmod_ctx *ctx, const char *alias, flags |= KMOD_PROBE_IGNORE_LOADED; if (dry_run) flags |= KMOD_PROBE_DRY_RUN; - if (do_show || verbose > DEFAULT_VERBOSE) - show = &print_action; flags |= KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY; @@ -608,36 +644,7 @@ static int insmod(struct kmod_ctx *ctx, const char *alias, kmod_list_foreach(l, list) { struct kmod_module *mod = kmod_module_get_module(l); - - if (lookup_only) - printf("%s\n", kmod_module_get_name(mod)); - else { - err = kmod_module_probe_insert_module(mod, flags, - extra_options, NULL, NULL, show); - } - - if (err >= 0) - /* ignore flag return values such as a mod being blacklisted */ - err = 0; - else { - switch (err) { - case -EEXIST: - ERR("could not insert '%s': Module already in kernel\n", - kmod_module_get_name(mod)); - break; - case -ENOENT: - ERR("could not insert '%s': Unknown symbol in module, " - "or unknown parameter (see dmesg)\n", - kmod_module_get_name(mod)); - break; - default: - ERR("could not insert '%s': %s\n", - kmod_module_get_name(mod), - strerror(-err)); - break; - } - } - + err = insmod_insert(mod, flags, extra_options); kmod_module_unref(mod); }