char *pathname;
char *aliases;
char *deps;
+ smallint open_read_failed;
} module_info;
/*
#endif
}
-static void parse_module(module_info *info, const char *pathname)
+/* Returns !0 if open/read was unsuccessful */
+static int parse_module(module_info *info, const char *pathname)
{
char *module_image;
char *ptr;
dbg1_error_msg("parse_module('%s')", pathname);
/* Read (possibly compressed) module */
+ errno = 0;
len = 64 * 1024 * 1024; /* 64 Mb at most */
module_image = xmalloc_open_zipped_read_close(pathname, &len);
/* module_image == NULL is ok here, find_keyword handles it */
dbg2_error_msg("dep:'%s'", ptr);
append(ptr);
}
+ free(module_image);
info->deps = copy_stringbuf();
- free(module_image);
+ info->open_read_failed = (module_image == NULL);
+ return info->open_read_failed;
}
static FAST_FUNC int fileAction(const char *pathname,
dbg1_error_msg("'%s' module name matches", pathname);
module_found_idx = cur;
- parse_module(&modinfo[cur], pathname);
+ if (parse_module(&modinfo[cur], pathname) != 0)
+ return TRUE; /* failed to open/read it, no point in trying loading */
if (!(option_mask32 & OPT_r)) {
if (load_module(pathname, module_load_options) == 0) {
#define process_module(a,b) process_module(a)
#define cmdline_options ""
#endif
-static void process_module(char *name, const char *cmdline_options)
+static int process_module(char *name, const char *cmdline_options)
{
char *s, *deps, *options;
module_info **infovec;
module_info *info;
int infoidx;
int is_remove = (option_mask32 & OPT_r) != 0;
+ int exitcode = EXIT_SUCCESS;
dbg1_error_msg("process_module('%s','%s')", name, cmdline_options);
* (compat note: this allows and strips .ko suffix)
*/
rmmod(name);
- return;
+ return EXIT_SUCCESS;
}
/*
*/
if (!is_remove && already_loaded(name)) {
dbg1_error_msg("nothing to do for '%s'", name);
- return;
+ return EXIT_SUCCESS;
}
options = NULL;
dbg1_error_msg("'%s': blacklisted", info->pathname);
continue;
}
+ if (info->open_read_failed) {
+ /* We already tried it, didn't work. Don't try load again */
+ exitcode = EXIT_FAILURE;
+ continue;
+ }
errno = 0;
if (load_module(info->pathname, options) != 0) {
if (EEXIST != errno) {
info->pathname,
moderror(errno));
}
+ exitcode = EXIT_FAILURE;
}
}
ret:
free(infovec);
free(options);
-//TODO: return load attempt result from process_module.
-//If dep didn't load ok, continuing makes little sense.
+
+ return exitcode;
}
#undef cmdline_options
int modprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int modprobe_main(int argc UNUSED_PARAM, char **argv)
{
+ int exitcode;
struct utsname uts;
char applet0 = applet_name[0];
IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(char *options;)
bb_error_msg_and_die("can't insert '%s': %s",
*argv, moderror(errno));
}
- return 0;
+ return EXIT_SUCCESS;
}
/* Try to load modprobe.dep.bb */
- if ('r' != applet0) /* not rmmod */
+ if ('r' != applet0) { /* not rmmod */
load_dep_bb();
+ }
/* Load/remove modules.
* Only rmmod/modprobe -r loops here, insmod/modprobe has only argv[0] */
+ exitcode = EXIT_SUCCESS;
do {
- process_module(*argv, options);
+ exitcode |= process_module(*argv, options);
} while (*++argv);
if (ENABLE_FEATURE_CLEAN_UP) {
IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(free(options);)
}
- return EXIT_SUCCESS;
+ return exitcode;
}