2008-08-20 17:00:34 +03:00
|
|
|
--- a/modutils/insmod.c
|
|
|
|
+++ b/modutils/insmod.c
|
2011-04-20 05:56:23 +03:00
|
|
|
@@ -11,6 +11,99 @@
|
2009-05-25 20:15:39 +03:00
|
|
|
|
2007-10-05 03:27:49 +03:00
|
|
|
#include "libbb.h"
|
2009-05-25 20:15:39 +03:00
|
|
|
#include "modutils.h"
|
2009-05-27 16:21:48 +03:00
|
|
|
+#include <sys/utsname.h>
|
2009-05-25 20:15:39 +03:00
|
|
|
+#ifndef CONFIG_FEATURE_2_4_MODULES
|
2007-10-05 03:27:49 +03:00
|
|
|
+#include <sys/mman.h>
|
|
|
|
+#include <asm/unistd.h>
|
|
|
|
+#include <sys/syscall.h>
|
|
|
|
+#endif
|
2009-05-25 16:52:31 +03:00
|
|
|
+
|
2007-10-05 03:27:49 +03:00
|
|
|
+static char *g_filename = NULL;
|
|
|
|
+
|
2009-05-25 16:52:31 +03:00
|
|
|
+static int FAST_FUNC check_module_name_match(const char *filename, struct stat *statbuf,
|
2007-10-05 03:27:49 +03:00
|
|
|
+ void *userdata, int depth)
|
|
|
|
+{
|
|
|
|
+ char *fullname = (char *) userdata;
|
2007-11-10 18:51:11 +02:00
|
|
|
+ char *tmp;
|
2007-10-05 03:27:49 +03:00
|
|
|
+
|
|
|
|
+ if (fullname[0] == '\0')
|
|
|
|
+ return FALSE;
|
2007-11-10 18:51:11 +02:00
|
|
|
+
|
|
|
|
+ tmp = bb_get_last_path_component_nostrip(filename);
|
|
|
|
+ if (strcmp(tmp, fullname) == 0) {
|
|
|
|
+ /* Stop searching if we find a match */
|
|
|
|
+ g_filename = xstrdup(filename);
|
|
|
|
+ return FALSE;
|
2007-10-05 03:27:49 +03:00
|
|
|
+ }
|
2007-11-10 18:51:11 +02:00
|
|
|
+
|
2007-10-05 03:27:49 +03:00
|
|
|
+ return TRUE;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int find_module(char *filename)
|
|
|
|
+{
|
|
|
|
+ char *module_dir, real_module_dir[FILENAME_MAX];
|
|
|
|
+ int len, slen, ret = ENOENT, k_version;
|
|
|
|
+ struct utsname myuname;
|
|
|
|
+ const char *suffix;
|
|
|
|
+ struct stat st;
|
|
|
|
+
|
|
|
|
+ /* check the kernel version */
|
|
|
|
+ if ((uname(&myuname) != 0) || (myuname.release[0] != '2'))
|
|
|
|
+ return EINVAL;
|
|
|
|
+
|
|
|
|
+ k_version = myuname.release[2] - '0';
|
|
|
|
+#if ENABLE_FEATURE_2_4_MODULES
|
|
|
|
+ if (k_version <= 4)
|
|
|
|
+ suffix = ".o";
|
|
|
|
+ else
|
2008-08-20 17:00:34 +03:00
|
|
|
+#endif
|
2007-10-05 03:27:49 +03:00
|
|
|
+ suffix = ".ko";
|
|
|
|
+
|
|
|
|
+ len = strlen(filename);
|
|
|
|
+ slen = strlen(suffix);
|
|
|
|
+
|
|
|
|
+ /* check for suffix and absolute path first */
|
|
|
|
+ if ((len < slen + 2) || (strcmp(filename + len - slen, suffix) != 0)) {
|
|
|
|
+ filename = xasprintf("%s%s", filename, suffix);
|
|
|
|
+ } else {
|
|
|
|
+ filename = strdup(filename);
|
2007-10-24 19:43:25 +03:00
|
|
|
+ if ((stat(filename, &st) == 0) && S_ISREG(st.st_mode)) {
|
|
|
|
+ g_filename = filename;
|
2007-10-05 03:27:49 +03:00
|
|
|
+ return 0;
|
2007-10-24 19:43:25 +03:00
|
|
|
+ }
|
|
|
|
+ free(filename);
|
|
|
|
+ return ENOENT;
|
2007-10-05 03:27:49 +03:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* next: scan /lib/modules/<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... */
|
2009-05-25 20:15:39 +03:00
|
|
|
+ module_dir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, myuname.release);
|
2007-10-05 03:27:49 +03:00
|
|
|
+ if (realpath(module_dir, real_module_dir) != NULL) {
|
|
|
|
+ free(module_dir);
|
|
|
|
+ module_dir = real_module_dir;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ recursive_action(module_dir, ACTION_RECURSE,
|
|
|
|
+ check_module_name_match, 0, filename, 0);
|
|
|
|
+
|
|
|
|
+ /* Check if we have a complete path */
|
2007-10-08 23:31:17 +03:00
|
|
|
+ if (g_filename == NULL)
|
|
|
|
+ goto done;
|
|
|
|
+
|
|
|
|
+ if ((stat(g_filename, &st) == 0) && S_ISREG(st.st_mode))
|
|
|
|
+ ret = 0;
|
|
|
|
+ else
|
|
|
|
+ free(g_filename);
|
2008-08-20 17:00:34 +03:00
|
|
|
+
|
2007-10-08 23:31:17 +03:00
|
|
|
+done:
|
2007-10-05 03:27:49 +03:00
|
|
|
+ free(filename);
|
2008-08-20 17:00:34 +03:00
|
|
|
+
|
2007-10-05 16:05:22 +03:00
|
|
|
+ return ret;
|
2009-05-25 20:15:39 +03:00
|
|
|
+}
|
2007-10-05 03:27:49 +03:00
|
|
|
|
2010-08-15 13:06:58 +03:00
|
|
|
/* 2.6 style insmod has no options and required filename
|
|
|
|
* (not module name - .ko can't be omitted) */
|
2011-04-20 05:56:23 +03:00
|
|
|
@@ -59,9 +152,15 @@ int insmod_main(int argc UNUSED_PARAM, c
|
2007-10-05 03:27:49 +03:00
|
|
|
if (!filename)
|
|
|
|
bb_show_usage();
|
|
|
|
|
2009-05-25 20:15:39 +03:00
|
|
|
- rc = bb_init_module(filename, parse_cmdline_module_options(argv));
|
|
|
|
+ rc = find_module(filename);
|
|
|
|
+ if (rc || (g_filename == NULL))
|
|
|
|
+ goto done;
|
2007-10-05 03:27:49 +03:00
|
|
|
+
|
2009-05-25 20:15:39 +03:00
|
|
|
+ rc = bb_init_module(g_filename, parse_cmdline_module_options(argv));
|
|
|
|
if (rc)
|
2009-09-28 15:38:46 +03:00
|
|
|
bb_error_msg("can't insert '%s': %s", filename, moderror(rc));
|
2009-05-25 20:15:39 +03:00
|
|
|
+ free (g_filename);
|
2009-09-28 15:38:46 +03:00
|
|
|
|
2007-10-05 03:27:49 +03:00
|
|
|
+done:
|
2009-05-25 20:15:39 +03:00
|
|
|
return rc;
|
2007-10-05 03:27:49 +03:00
|
|
|
}
|
2010-08-15 12:53:21 +03:00
|
|
|
--- a/modutils/Config.src
|
|
|
|
+++ b/modutils/Config.src
|
2011-04-20 05:56:23 +03:00
|
|
|
@@ -229,7 +229,7 @@ config FEATURE_MODUTILS_SYMBOLS
|
2009-09-28 15:38:46 +03:00
|
|
|
config DEFAULT_MODULES_DIR
|
|
|
|
string "Default directory containing modules"
|
|
|
|
default "/lib/modules"
|
2010-08-15 12:53:21 +03:00
|
|
|
- depends on DEPMOD || MODPROBE || MODPROBE_SMALL || MODINFO
|
2010-08-15 23:28:05 +03:00
|
|
|
+ depends on DEPMOD || INSMOD || MODPROBE || MODPROBE_SMALL || MODINFO
|
2009-09-28 15:38:46 +03:00
|
|
|
help
|
|
|
|
Directory that contains kernel modules.
|
|
|
|
Defaults to "/lib/modules"
|