1 --- a/modutils/Config.src
2 +++ b/modutils/Config.src
3 @@ -247,7 +247,7 @@ config FEATURE_MODUTILS_SYMBOLS
4 config DEFAULT_MODULES_DIR
5 string "Default directory containing modules"
7 - depends on DEPMOD || MODPROBE || MODPROBE_SMALL || MODINFO
8 + depends on DEPMOD || INSMOD || MODPROBE || MODPROBE_SMALL || MODINFO
10 Directory that contains kernel modules.
11 Defaults to "/lib/modules"
12 --- a/modutils/insmod.c
13 +++ b/modutils/insmod.c
18 +#include <sys/utsname.h>
19 +#ifndef CONFIG_FEATURE_2_4_MODULES
20 +#include <sys/mman.h>
21 +#include <asm/unistd.h>
22 +#include <sys/syscall.h>
25 +static char *g_filename = NULL;
27 +static int FAST_FUNC check_module_name_match(const char *filename, struct stat *statbuf,
28 + void *userdata, int depth)
30 + char *fullname = (char *) userdata;
33 + if (fullname[0] == '\0')
36 + tmp = bb_get_last_path_component_nostrip(filename);
37 + if (strcmp(tmp, fullname) == 0) {
38 + /* Stop searching if we find a match */
39 + g_filename = xstrdup(filename);
46 +static int find_module(char *filename)
48 + char *module_dir, real_module_dir[FILENAME_MAX];
49 + int len, slen, ret = ENOENT, k_version;
50 + struct utsname myuname;
51 + const char *suffix = ".ko";
54 + /* check the kernel version */
55 + if (uname(&myuname) != 0)
58 + k_version = myuname.release[0] - '0';
60 + if (k_version < 2 || k_version > 9)
63 + if (k_version == 2) {
64 + int k_patchlevel = myuname.release[2] - '0';
65 + if (k_patchlevel <= 4)
66 +#if ENABLE_FEATURE_2_4_MODULES
73 + len = strlen(filename);
74 + slen = strlen(suffix);
76 + /* check for suffix and absolute path first */
77 + if ((len < slen + 2) || (strcmp(filename + len - slen, suffix) != 0)) {
78 + filename = xasprintf("%s%s", filename, suffix);
80 + filename = strdup(filename);
81 + if ((stat(filename, &st) == 0) && S_ISREG(st.st_mode)) {
82 + g_filename = filename;
89 + /* next: scan /lib/modules/<release> */
90 + /* Jump through hoops in case /lib/modules/`uname -r`
91 + * is a symlink. We do not want recursive_action to
92 + * follow symlinks, but we do want to follow the
93 + * /lib/modules/`uname -r` dir, So resolve it ourselves
94 + * if it is a link... */
95 + module_dir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, myuname.release);
96 + if (realpath(module_dir, real_module_dir) != NULL) {
98 + module_dir = real_module_dir;
101 + recursive_action(module_dir, ACTION_RECURSE,
102 + check_module_name_match, 0, filename, 0);
104 + /* Check if we have a complete path */
105 + if (g_filename == NULL)
108 + if ((stat(g_filename, &st) == 0) && S_ISREG(st.st_mode))
119 /* 2.6 style insmod has no options and required filename
120 * (not module name - .ko can't be omitted) */
121 @@ -58,9 +158,15 @@ int insmod_main(int argc UNUSED_PARAM, c
125 - rc = bb_init_module(filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0));
126 + rc = find_module(filename);
127 + if (rc || (g_filename == NULL))
130 + rc = bb_init_module(g_filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0));
132 bb_error_msg("can't insert '%s': %s", filename, moderror(rc));