Skip to content
Snippets Groups Projects
Commit 58e8071e authored by Lucas Magalhães's avatar Lucas Magalhães
Browse files

Remove registerExternalModules

The E3 does not use modules linked out of require so this code is
superfluous here. It was used to register require itself however the
code complexity was not justified for such simple task. To fulfill
this a simpler function was added just to register require.
parent b0ecf5b4
No related branches found
No related tags found
1 merge request!144Mixed rewrites of require functions
...@@ -97,6 +97,9 @@ int requireDebug; ...@@ -97,6 +97,9 @@ int requireDebug;
#define TEMPLATEDIR "db" #define TEMPLATEDIR "db"
#define LIBRELEASE "LibRelease" #define LIBRELEASE "LibRelease"
#define E3_REQUIRE_LOCATION "E3_REQUIRE_LOCATION"
#define E3_REQUIRE_VERSION "E3_REQUIRE_VERSION"
#ifndef OS_CLASS #ifndef OS_CLASS
#error OS_CLASS not defined: Try to compile with USR_CFLAGS += -DOS_CLASS='"${OS_CLASS}"' #error OS_CLASS not defined: Try to compile with USR_CFLAGS += -DOS_CLASS='"${OS_CLASS}"'
#endif // OS_CLASS #endif // OS_CLASS
...@@ -260,70 +263,24 @@ static void fillModuleListRecord(initHookState state) { ...@@ -260,70 +263,24 @@ static void fillModuleListRecord(initHookState state) {
} }
} }
#if defined(__linux) static int registerRequire(){
/* This is the Linux link.h, not the EPICS link.h ! */ char *requireLocation = NULL;
#include <link.h> char *requireVersion = NULL;
static int findLibRelease(struct dl_phdr_info *info, /* shared library info */
size_t size, /* size of info structure */
void *data /* user-supplied arg */
) {
void *handle = NULL;
char *location = NULL;
char *p = NULL;
char *version = NULL;
char *symname = NULL;
/* get space for library path + "LibRelease" */
char name[PATH_MAX + (sizeof(LIBRELEASE)/sizeof(char))] = {0};
struct linkedList *linkedlist = (struct linkedList*)data;
if (size < sizeof(struct dl_phdr_info))
return 0; /* wrong version of struct dl_phdr_info */
/* find a symbol with a name like "_<module>LibRelease"
where <module> is from the library name "<location>/lib<module>.so" */
/* no library name */
if (info->dlpi_name == NULL || info->dlpi_name[0] == 0) return 0;
/* get a modifiable copy of the library name */
strcpy(name, info->dlpi_name);
/* re-open already loaded library */
handle = dlopen(info->dlpi_name, RTLD_LAZY);
/* find file name part in "<location>/lib<module>.so" */
p = strrchr(name, '/');
if (p) {
location = name;
*++p = 0;
} else {
/* terminate "<location>/" (if exists) */
p = name;
}
*(symname = p + 2) = '_'; /* replace "lib" with "_" */
p = strchr(symname, '.'); /* find ".so" extension */
if (p == NULL) p = symname + strnlen(symname, PATH_MAX); /* no file extension ? */
strcpy(p, LIBRELEASE); /* append "LibRelease" to module name */
version = dlsym(handle, symname); /* find symbol "_<module>LibRelease" */
if (version) {
*p = 0;
symname++; /* get "<module>" from "_<module>LibRelease" */
if ((p = strstr(name, "/" LIBDIR)) != NULL)
p[1] = 0; /* cut "<location>" before LIBDIR */
if (getLibVersion(linkedlist, symname) == NULL)
registerModule(linkedlist, symname, version, location);
}
dlclose(handle);
return 0;
}
static void registerExternalModules() { requireLocation = getenv(E3_REQUIRE_LOCATION);
/* iterate over all loaded libraries */ if (!requireLocation){
dl_iterate_phdr(findLibRelease, (void *)&loadedModules); printf("require: Failed to get " E3_REQUIRE_LOCATION "\n");
return -1;
}
requireVersion = getenv(E3_REQUIRE_VERSION);
if (!requireVersion){
printf("require: Failed to get " E3_REQUIRE_VERSION "\n");
return -1;
}
registerModule(&loadedModules, "require", requireVersion, requireLocation);
return 0;
} }
#else
static void registerExternalModules() { ; }
#endif
int libversionShow(const char *outfile) { int libversionShow(const char *outfile) {
struct module *m = NULL; struct module *m = NULL;
...@@ -1000,7 +957,9 @@ static void requireRegister(void) { ...@@ -1000,7 +957,9 @@ static void requireRegister(void) {
iocshRegister(&libversionShowDef, libversionShowFunc); iocshRegister(&libversionShowDef, libversionShowFunc);
iocshRegister(&ldDef, ldFunc); iocshRegister(&ldDef, ldFunc);
iocshRegister(&pathAddDef, pathAddFunc); iocshRegister(&pathAddDef, pathAddFunc);
registerExternalModules(); if(registerRequire() != 0){
printf("require: Could not register require.\n");
}
set_require_env(); set_require_env();
initHookRegister(fillModuleListRecord); initHookRegister(fillModuleListRecord);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment