1 --- a/modutils/insmod.c
2 +++ b/modutils/insmod.c
7 +#include <sys/utsname.h>
8 +#ifndef CONFIG_FEATURE_2_4_MODULES
10 +#include <asm/unistd.h>
11 +#include <sys/syscall.h>
14 +static char *g_filename = NULL;
16 +static int FAST_FUNC check_module_name_match(const char *filename, struct stat *statbuf,
17 + void *userdata, int depth)
19 + char *fullname = (char *) userdata;
22 + if (fullname[0] == '\0')
25 + tmp = bb_get_last_path_component_nostrip(filename);
26 + if (strcmp(tmp, fullname) == 0) {
27 + /* Stop searching if we find a match */
28 + g_filename = xstrdup(filename);
35 +static int find_module(char *filename)
37 + char *module_dir, real_module_dir[FILENAME_MAX];
38 + int len, slen, ret = ENOENT, k_version;
39 + struct utsname myuname;
43 + /* check the kernel version */
44 + if ((uname(&myuname) != 0) || (myuname.release[0] != '2'))
47 + k_version = myuname.release[2] - '0';
48 +#if ENABLE_FEATURE_2_4_MODULES
55 + len = strlen(filename);
56 + slen = strlen(suffix);
58 + /* check for suffix and absolute path first */
59 + if ((len < slen + 2) || (strcmp(filename + len - slen, suffix) != 0)) {
60 + filename = xasprintf("%s%s", filename, suffix);
62 + filename = strdup(filename);
63 + if ((stat(filename, &st) == 0) && S_ISREG(st.st_mode)) {
64 + g_filename = filename;
71 + /* next: scan /lib/modules/<release> */
72 + /* Jump through hoops in case /lib/modules/`uname -r`
73 + * is a symlink. We do not want recursive_action to
74 + * follow symlinks, but we do want to follow the
75 + * /lib/modules/`uname -r` dir, So resolve it ourselves
76 + * if it is a link... */
77 + module_dir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, myuname.release);
78 + if (realpath(module_dir, real_module_dir) != NULL) {
80 + module_dir = real_module_dir;
83 + recursive_action(module_dir, ACTION_RECURSE,
84 + check_module_name_match, 0, filename, 0);
86 + /* Check if we have a complete path */
87 + if (g_filename == NULL)
90 + if ((stat(g_filename, &st) == 0) && S_ISREG(st.st_mode))
101 int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
102 int insmod_main(int argc UNUSED_PARAM, char **argv)
103 @@ -33,9 +126,15 @@ int insmod_main(int argc UNUSED_PARAM, c
107 - rc = bb_init_module(filename, parse_cmdline_module_options(argv));
108 + rc = find_module(filename);
109 + if (rc || (g_filename == NULL))
112 + rc = bb_init_module(g_filename, parse_cmdline_module_options(argv));
114 bb_error_msg("can't insert '%s': %s", filename, moderror(rc));
120 --- a/modutils/Config.in
121 +++ b/modutils/Config.in
122 @@ -210,7 +210,7 @@ config FEATURE_MODUTILS_SYMBOLS
123 config DEFAULT_MODULES_DIR
124 string "Default directory containing modules"
125 default "/lib/modules"
126 - depends on DEPMOD || MODPROBE || MODPROBE_SMALL
127 + depends on DEPMOD || INSMOD || MODPROBE || MODPROBE_SMALL
129 Directory that contains kernel modules.
130 Defaults to "/lib/modules"