1 --- busybox/modutils/insmod.c 2007-05-11 12:10:43.000000000 +0200
2 +++ busybox/modutils/insmod.c 2007-05-11 12:12:15.000000000 +0200
4 extern int insmod_ng_main( int argc, char **argv);
7 +static char *m_filename;
8 +static char *m_fullName;
9 +#define _PATH_MODULES "/lib/modules"
11 +static int check_module_name_match(const char *filename, struct stat *statbuf,
12 + void *userdata, int depth)
14 + char *fullname = (char *) userdata;
16 + if (fullname[0] == '\0')
19 + char *tmp, *tmp1 = xstrdup(filename);
20 + tmp = bb_get_last_path_component(tmp1);
21 + if (strcmp(tmp, fullname) == 0) {
23 + /* Stop searching if we find a match */
24 + m_filename = xstrdup(filename);
32 #if ENABLE_FEATURE_2_4_MODULES
38 -#define _PATH_MODULES "/lib/modules"
39 enum { STRVERSIONLEN = 64 };
41 /*======================================================================*/
43 static int n_ext_modules_used;
44 extern int delete_module(const char *);
46 -static char *m_filename;
47 -static char *m_fullName;
50 -/*======================================================================*/
53 -static int check_module_name_match(const char *filename, struct stat *statbuf,
54 - void *userdata, int depth)
56 - char *fullname = (char *) userdata;
58 - if (fullname[0] == '\0')
61 - char *tmp, *tmp1 = xstrdup(filename);
62 - tmp = bb_get_last_path_component(tmp1);
63 - if (strcmp(tmp, fullname) == 0) {
65 - /* Stop searching if we find a match */
66 - m_filename = xstrdup(filename);
75 -/*======================================================================*/
77 static struct obj_file *arch_new_file(void)
80 @@ -4265,14 +4257,97 @@
84 - char *filename, *options;
85 + char *options, *tmp;
87 +#if ENABLE_FEATURE_CLEAN_UP
93 + struct utsname myuname;
100 +#if !ENABLE_FEATURE_2_4_MODULES
101 + /* Grab the module name */
102 + tmp = basename(xstrdup(argv[1]));
105 + if (uname(&myuname) == 0) {
106 + if (myuname.release[0] == '2') {
107 + k_version = myuname.release[2] - '0';
111 + if (len > 3 && tmp[len - 3] == '.' && tmp[len - 2] == 'k' && tmp[len - 1] == 'o') {
117 + m_fullName = xasprintf("%s.ko", tmp);
119 + /* Get a filedesc for the module. Check we we have a complete path */
120 + if (stat(argv[1], &st) < 0 || !S_ISREG(st.st_mode)
121 + || (fp = fopen(argv[1], "r")) == NULL
123 + /* Hmm. Could not open it. First search under /lib/modules/`uname -r`,
124 + * but do not error out yet if we fail to find it... */
125 + if (k_version) { /* uname succeedd */
128 + char real_module_dir[FILENAME_MAX];
130 + tmdn = concat_path_file(_PATH_MODULES, myuname.release);
131 + /* Jump through hoops in case /lib/modules/`uname -r`
132 + * is a symlink. We do not want recursive_action to
133 + * follow symlinks, but we do want to follow the
134 + * /lib/modules/`uname -r` dir, So resolve it ourselves
135 + * if it is a link... */
136 + if (realpath(tmdn, real_module_dir) == NULL)
139 + module_dir = real_module_dir;
140 + recursive_action(module_dir, TRUE, FALSE, FALSE,
141 + check_module_name_match, 0, m_fullName, 0);
145 + /* Check if we have found anything yet */
146 + if (m_filename == 0 || ((fp = fopen(m_filename, "r")) == NULL)) {
147 + char module_dir[FILENAME_MAX];
151 + if (realpath (_PATH_MODULES, module_dir) == NULL)
152 + strcpy(module_dir, _PATH_MODULES);
153 + /* No module found under /lib/modules/`uname -r`, this
154 + * time cast the net a bit wider. Search /lib/modules/ */
155 + if (!recursive_action(module_dir, TRUE, FALSE, FALSE,
156 + check_module_name_match, 0, m_fullName, 0)
158 + if (m_filename == 0
159 + || ((fp = fopen(m_filename, "r")) == NULL)
161 + bb_error_msg("%s: no module by that name found", m_fullName);
162 +#if ENABLE_FEATURE_CLEAN_UP
169 + bb_error_msg_and_die("%s: no module by that name found", m_fullName);
172 + m_filename = xstrdup(argv[1]);
175 /* Rest is options */
176 options = xstrdup("");
179 int optlen = strlen(options);
180 options = xrealloc(options, optlen + 2 + strlen(*argv) + 2);
181 @@ -4300,13 +4375,13 @@
184 len = MAXINT(ssize_t);
185 - map = xmalloc_open_read_close(filename, &len);
186 + map = xmalloc_open_read_close(m_filename, &len);
189 ret = syscall(__NR_init_module, map, len, options);
191 bb_perror_msg_and_die("cannot insert '%s': %s (%li)",
192 - filename, moderror(errno), ret);
193 + m_filename, moderror(errno), ret);