aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/sys/module/common.c
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@linux.intel.com>2011-06-06 11:09:42 +0100
committerMatt Fleming <matt.fleming@linux.intel.com>2011-06-06 11:09:42 +0100
commitef3cb76bffc52b40b9a013f5b16835e062a5db4b (patch)
tree873d1fd526d9fa5a8ca10dcaac114c1dae27fa5e /com32/lib/sys/module/common.c
parentba4fefa9b52b25ca1babd77066e21abef19518c2 (diff)
downloadsyslinux-ef3cb76bffc52b40b9a013f5b16835e062a5db4b.tar.gz
syslinux-ef3cb76bffc52b40b9a013f5b16835e062a5db4b.tar.xz
syslinux-ef3cb76bffc52b40b9a013f5b16835e062a5db4b.zip
ldlinux: PATH-based module lookup
Add support for specifying directories to search when loading modules. A new config directive, "PATH", instructs the module loading code to search the directories listed in a colon-separated list when loading a module. Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
Diffstat (limited to 'com32/lib/sys/module/common.c')
-rw-r--r--com32/lib/sys/module/common.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c
index 431f5cd4..1afdbf5f 100644
--- a/com32/lib/sys/module/common.c
+++ b/com32/lib/sys/module/common.c
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <elf.h>
#include <string.h>
+#include <fs.h>
#include <linux/list.h>
#include <sys/module.h>
@@ -56,13 +57,45 @@ void print_elf_symbols(struct elf_module *module) {
}
#endif //ELF_DEBUG
+static FILE *findpath(char *name)
+{
+ char path[FILENAME_MAX];
+ FILE *f;
+ char *p, *n;
+ int i;
+
+ p = PATH;
+again:
+ i = 0;
+ while (*p && *p != ':' && i < FILENAME_MAX) {
+ path[i++] = *p++;
+ }
+
+ if (*p == ':')
+ p++;
+
+ n = name;
+ while (*n && i < FILENAME_MAX)
+ path[i++] = *n++;
+ path[i] = '\0';
+
+ f = fopen(path, "rb");
+ if (f)
+ return f;
+
+ if (p >= PATH && p < PATH + strlen(PATH))
+ goto again;
+
+ return NULL;
+}
+
/*
* Image files manipulation routines
*/
int image_load(struct elf_module *module)
{
- module->u.l._file = fopen(module->name, "rb");
+ module->u.l._file = findpath(module->name);
if (module->u.l._file == NULL) {
DBG_PRINT("Could not open object file '%s'\n", module->name);