mirror of
https://github.com/AuxXxilium/kmod.git
synced 2024-11-23 23:10:53 +07:00
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 <gustavo.sousa@intel.com> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This commit is contained in:
parent
e54f74c4f7
commit
f3db15e900
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user