- /* Parse any options */
- getopt32(argv, OPTION_STR, &opt_o);
- arg1 = argv[optind];
-@@ -3987,110 +4043,18 @@
- m_name = xstrdup(opt_o);
- }
-
-- if (arg1 == NULL) {
-+ if (arg1 == NULL)
- bb_show_usage();
-- }
--
-- /* Grab the module name */
-- tmp1 = xstrdup(arg1);
-- tmp = basename(tmp1);
-- len = strlen(tmp);
--
-- if (uname(&myuname) == 0) {
-- if (myuname.release[0] == '2') {
-- k_version = myuname.release[2] - '0';
-- }
-- }
--
--#if ENABLE_FEATURE_2_6_MODULES
-- if (k_version > 4 && len > 3 && tmp[len - 3] == '.'
-- && tmp[len - 2] == 'k' && tmp[len - 1] == 'o'
-- ) {
-- len -= 3;
-- tmp[len] = '\0';
-- } else
--#endif
-- if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o') {
-- len -= 2;
-- tmp[len] = '\0';
-- }
--
--
--#if ENABLE_FEATURE_2_6_MODULES
-- if (k_version > 4)
-- m_fullName = xasprintf("%s.ko", tmp);
-- else
--#endif
-- m_fullName = xasprintf("%s.o", tmp);
-
-- if (!m_name) {
-- m_name = tmp;
-- } else {
-- free(tmp1);
-- tmp1 = 0; /* flag for free(m_name) before exit() */
-- }
--
-- /* Get a filedesc for the module. Check we we have a complete path */
-- if (stat(arg1, &st) < 0 || !S_ISREG(st.st_mode)
-- || (fp = fopen(arg1, "r")) == NULL
-- ) {
-- /* Hmm. Could not open it. First search under /lib/modules/`uname -r`,
-- * but do not error out yet if we fail to find it... */
-- if (k_version) { /* uname succeedd */
-- char *module_dir;
-- char *tmdn;
-- char real_module_dir[FILENAME_MAX];
--
-- tmdn = concat_path_file(_PATH_MODULES, myuname.release);
-- /* Jump through hoops in case /lib/modules/`uname -r`
-- * is a symlink. We do not want recursive_action to
-- * follow symlinks, but we do want to follow the
-- * /lib/modules/`uname -r` dir, So resolve it ourselves
-- * if it is a link... */
-- if (realpath(tmdn, real_module_dir) == NULL)
-- module_dir = tmdn;
-- else
-- module_dir = real_module_dir;
-- recursive_action(module_dir, ACTION_RECURSE,
-- check_module_name_match, 0, m_fullName, 0);
-- free(tmdn);
-- }
--
-- /* Check if we have found anything yet */
-- if (m_filename == 0 || ((fp = fopen(m_filename, "r")) == NULL)) {
-- char module_dir[FILENAME_MAX];
--
-- free(m_filename);
-- m_filename = 0;
-- if (realpath (_PATH_MODULES, module_dir) == NULL)
-- strcpy(module_dir, _PATH_MODULES);
-- /* No module found under /lib/modules/`uname -r`, this
-- * time cast the net a bit wider. Search /lib/modules/ */
-- if (!recursive_action(module_dir, ACTION_RECURSE,
-- check_module_name_match, 0, m_fullName, 0)
-- ) {
-- if (m_filename == 0
-- || ((fp = fopen(m_filename, "r")) == NULL)
-- ) {
-- bb_error_msg("%s: no module by that name found", m_fullName);
-- goto out;
-- }
-- } else
-- bb_error_msg_and_die("%s: no module by that name found", m_fullName);
-- }
-- } else
-- m_filename = xstrdup(arg1);
--
-- if (flag_verbose)
-- printf("Using %s\n", m_filename);
-+ ret = find_module(arg1);
-+ if (ret)
-+ goto out;
-
--#if ENABLE_FEATURE_2_6_MODULES
-- if (k_version > 4) {
-- argv[optind] = m_filename;
-- optind--;
-- return insmod_ng_main(argc - optind, argv + optind);
-+ fp = fopen(g_filename, "r");
-+ if (!fp) {
-+ ret = errno;
-+ goto out;
- }
--#endif
-
- f = obj_load(fp, LOADBITS);
- if (f == NULL)
-@@ -4120,7 +4084,7 @@
- "\t%s was compiled for kernel version %s\n"
- "\twhile this kernel is version %s",
- flag_force_load ? "warning: " : "",
-- m_filename, m_strversion, uts_info.release);
-+ g_filename, m_strversion, uts_info.release);
- if (!flag_force_load)
- goto out;
- }
-@@ -4173,7 +4137,7 @@
- hide_special_symbols(f);
-
- #if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
-- add_ksymoops_symbols(f, m_filename, m_name);
-+ add_ksymoops_symbols(f, g_filename, m_name);
- #endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
-
- new_create_module_ksymtab(f);
-@@ -4220,8 +4184,7 @@
- if (flag_print_load_map)
- print_load_map(f);
-
-- exit_status = EXIT_SUCCESS;
--
-+ ret = 0;
- out:
- #if ENABLE_FEATURE_CLEAN_UP
- if (fp)
-@@ -4229,21 +4192,13 @@
- free(tmp1);
- if (!tmp1)
- free(m_name);
-- free(m_filename);
-+ free(g_filename);
- #endif
-- return exit_status;