Subject: Re: Handling multiple lkm's
To: Bill Studenmund <wrstuden@loki.stanford.edu>
From: Darren Reed <darrenr@cyber.com.au>
List: tech-kern
Date: 09/13/1997 12:15:12
In some mail I received from Bill Studenmund, sie wrote
>
> >
> > I thought that modload doesn't assume one now, forcing you to specify the
> > entry point with -e, which is what everyone seemed to be trying to
> > avoid here in this thread. Of course, if I am completely without clue,
> > please help me find one :-)
>
> I think all the lkm samples set a precedent of using something other
> than xxxinit for the entry point, so everyone's always used something
> else, requiring explicit specification w/ -e. :-)
Well, after this little discourse, I made some quick changes and came up
with the patch below. If it can't find xxxinit then it looks for
<modname>_init. If you use -e, it won't try any other names. If people
are happy with this, I'll commit it.
btw, what's the deal with the _AOUT_INCLUDE_ bogosity or don't I want to
know ?
Cheers,
Darren
*** modload.c.orig Sat Sep 13 11:40:02 1997
--- modload.c Sat Sep 13 12:09:14 1997
***************
*** 45,50 ****
--- 45,51 ----
#include <string.h>
#include <err.h>
#include <unistd.h>
+ #include <nlist.h>
#include "pathnames.h"
#ifndef DFLT_ENTRY
***************
*** 141,146 ****
--- 142,171 ----
}
int
+ verify_entry(entry, filename)
+ char *entry, *filename;
+ {
+ struct nlist names[2];
+ int n;
+
+ bzero((char *)names, sizeof(names));
+ #ifdef _AOUT_INCLUDE_
+ names[0].n_un.n_name = (char *)malloc(strlen(entry) + 2);
+ names[0].n_un.n_name[0] = '_';
+ strcpy(names[0].n_un.n_name + 1, entry);
+ #else
+ names[0].n_name = (char *)malloc(strlen(entry) + 2);
+ names[0].n_name[0] = '_';
+ strcpy(names[0].n_name + 1, entry);
+ #endif
+
+ n = nlist(filename, names);
+ if (n == -1)
+ errx(1, "file %s does not exist", filename);
+ return n;
+ }
+
+ int
main(argc, argv)
int argc;
char *argv[];
***************
*** 214,219 ****
--- 239,267 ----
if (out == NULL) {
out = modout;
*p = '\0';
+ }
+
+ /*
+ * Verify that the entry point for the module exists.
+ */
+ if (verify_entry(entry, modobj)) {
+ /*
+ * Try <modobj>_init if entry is DFLT_ENTRY.
+ */
+ if (entry == DFLT_ENTRY) {
+ if ((p = strrchr(modout, '/')))
+ p++;
+ else
+ p = modout;
+ entry = (char *)malloc(strlen(p) + 6);
+ strcpy(entry, p);
+ strcat(entry, "_init");
+ if (verify_entry(entry, modobj))
+ errx(1, "entry point _%s not found in %s",
+ entry, modobj);
+ } else
+ errx(1, "entry point _%s not found in %s", entry,
+ modobj);
}
/*