From e99f57c354c3298fe6aef6289512e59cfd3d29bb Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Sun, 17 Jan 1999 17:58:52 +0000 Subject: [PATCH] Try and clean up the multiple formal loading support a bit, based on suggestions from Greg Lehey some time ago. In the face of multiple potential file formats, try and give a more sensible error than just ENOEXEC. XXX a good case can be made that the loading process is wrong - the linker should locate the file first (using the search paths etc), then run the loaders to see if they recognize it. While the present system allows for the possibility of different search paths for different formats, we do not use it and it just makes things more complicated than they need to be. --- sys/kern/kern_linker.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c index 6eb229ec06e..4900784255c 100644 --- a/sys/kern/kern_linker.c +++ b/sys/kern/kern_linker.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: kern_linker.c,v 1.17 1998/11/11 13:04:39 peter Exp $ + * $Id: kern_linker.c,v 1.18 1999/01/05 20:24:28 msmith Exp $ */ #include "opt_ddb.h" @@ -237,7 +237,7 @@ linker_load_file(const char* filename, linker_file_t* result) { linker_class_t lc; linker_file_t lf; - int error = 0; + int foundfile, error = 0; char *koname = NULL; lf = linker_find_file_by_name(filename); @@ -255,16 +255,20 @@ linker_load_file(const char* filename, linker_file_t* result) } sprintf(koname, "%s.ko", filename); lf = NULL; + foundfile = 0; for (lc = TAILQ_FIRST(&classes); lc; lc = TAILQ_NEXT(lc, link)) { KLD_DPF(FILE, ("linker_load_file: trying to load %s as %s\n", filename, lc->desc)); - error = lc->ops->load_file(koname, &lf); - if (lf == NULL && error && error != ENOENT) - goto out; - if (lf == NULL) - error = lc->ops->load_file(filename, &lf); - if (lf == NULL && error && error != ENOENT) - goto out; + + error = lc->ops->load_file(koname, &lf); /* First with .ko */ + if (lf == NULL && error == ENOENT) + error = lc->ops->load_file(filename, &lf); /* Then try without */ + /* + * If we got something other than ENOENT, then it exists but we cannot + * load it for some other reason. + */ + if (error != ENOENT) + foundfile = 1; if (lf) { linker_file_sysinit(lf); @@ -273,7 +277,14 @@ linker_load_file(const char* filename, linker_file_t* result) goto out; } } - error = ENOEXEC; /* format not recognised */ + /* + * Less than ideal, but tells the user whether it failed to load or + * the module was not found. + */ + if (foundfile) + error = ENOEXEC; /* Format not recognised (or unloadable) */ + else + error = ENOENT; /* Nothing found */ out: if (koname)