diff --git a/require-ess/src/require.c b/require-ess/src/require.c index a19df00d168a0581ca0f5857ae4514bce496e655..7686f5d84af5eed31d85d982d2c075a7d92759e6 100644 --- a/require-ess/src/require.c +++ b/require-ess/src/require.c @@ -430,8 +430,8 @@ must wait until initHooks is loaded before we can register the hook. */ static void fillModuleListRecord(initHookState state) { - if (state == initHookAfterFinishDevSup) /* MODULES record exists and has - allocated memory */ { + /* MODULES record exists and has allocated memory */ + if (state == initHookAfterFinishDevSup) { DBADDR modules, versions, modver; int have_modules, have_versions, have_modver; moduleitem *m; @@ -519,7 +519,8 @@ void registerModule(const char *module, const char *version, strcpy(m->content + lm + lv, absLocation ? absLocation : ""); free(absLocation); - for (pm = &loadedModules; *pm != NULL; pm = &(*pm)->next) {} + for (pm = &loadedModules; *pm != NULL; pm = &(*pm)->next) { + } *pm = m; if (lm > maxModuleNameLength) maxModuleNameLength = lm; moduleListBufferSize += lv; @@ -578,28 +579,33 @@ static int findLibRelease(struct dl_phdr_info *info, /* shared library info */ char *p; char *version; char *symname; - char name[PATH_MAX + 11]; /* get space for library path + "LibRelease" */ + /* get space for library path + "LibRelease" */ + char name[PATH_MAX + 11]; (void)data; /* unused */ 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" */ - if (info->dlpi_name == NULL || info->dlpi_name[0] == 0) - return 0; /* no library name */ - strcpy(name, info->dlpi_name); /* get a modifiable copy of the library name */ - handle = - dlopen(info->dlpi_name, RTLD_LAZY); /* re-open already loaded library */ - p = strrchr(name, - '/'); /* find file name part in "<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 { - p = name; /* terminate "<location>/" (if exists) */ + /* terminate "<location>/" (if exists) */ + p = name; } - *(symname = p + 2) = '_'; /* replace "lib" with "_" */ - p = strchr(symname, '.'); /* find ".so" extension */ + *(symname = p + 2) = '_'; /* replace "lib" with "_" */ + p = strchr(symname, '.'); /* find ".so" extension */ if (p == NULL) p = symname + strlen(symname); /* no file extension ? */ strcpy(p, "LibRelease"); /* append "LibRelease" to module name */ version = dlsym(handle, symname); /* find symbol "_<module>LibRelease" */ @@ -631,7 +637,8 @@ static void registerExternalModules() { char *version; char *symname; unsigned int i; - char name[MAX_PATH + 11]; /* get space for library path + "LibRelease" */ + /* get space for library path + "LibRelease" */ + char name[MAX_PATH + 11]; /* iterate over all loaded libraries */ if (!EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) return; @@ -640,12 +647,14 @@ static void registerExternalModules() { if (!GetModuleFileName(hMods[i], name, MAX_PATH)) continue; /* no library name */ name[sizeof(name) - 1] = 0; /* WinXP may not terminate the string */ - p = strrchr(name, - '\\'); /* find file name part in "<location>/<module>.dll" */ + + /* find file name part in "<location>/<module>.dll" */ + p = strrchr(name, '\\'); if (p) { location = name; } else { - p = name; /* find end of "<location>\\" (if exists) */ + /* find end of "<location>\\" (if exists) */ + p = name; } symname = p; p = strchr(symname, '.'); /* find ".dll" */ @@ -1217,7 +1226,9 @@ static int require_priv( "%s" OSI_PATH_SEPARATOR LIBDIR "%s" OSI_PATH_SEPARATOR, currentFilename, targetArch)) { - /* filename = "<dirname>/[dirlen]<module>/[modulediroffs]<version>/lib/<targetArch>/" */ + /* filename = + * "<dirname>/[dirlen]<module>/[modulediroffs]<version>/lib/<targetArch>/" + */ if (requireDebug) printf("require: %s %s has no support for %s %s\n", module, currentFilename, epicsRelease, targetArch); @@ -1269,7 +1280,8 @@ static int require_priv( if (status == EXACT) break; } END_DIR_LOOP - } else { + } + else { /* filename = "<dirname>/[dirlen]<module>/" */ if (requireDebug) printf("require: no %s directory\n", filename); @@ -1279,9 +1291,9 @@ static int require_priv( /* look for dep file */ releasediroffs = libdiroffs = dirlen; if (TRY_FILE(dirlen, "%s%s.dep", module, versionstr)) { - /* filename = - "<dirname>/[dirlen][releasediroffs][libdiroffs]<module>(-<version>)?.dep" - */ + /* filename = + "<dirname>/[dirlen][releasediroffs][libdiroffs]<module>(-<version>)?.dep" + */ if (requireDebug) printf("require: found old style %s\n", filename); printf("Module %s%s found in %.*s\n", module, versionstr, dirlen, filename); @@ -1338,9 +1350,9 @@ static int require_priv( "%s" OSI_PATH_SEPARATOR "%n" LIBDIR "%s" OSI_PATH_SEPARATOR "%n%s.dep", founddir, &releasediroffs, targetArch, &libdiroffs, module)) { - /* filename = - "<dirname>/[dirlen]<module>/<version>/R<epicsRelease>/[releasediroffs]/lib/<targetArch>/[libdiroffs]/module.dep" - */ + /* filename = + "<dirname>/[dirlen]<module>/<version>/R<epicsRelease>/[releasediroffs]/lib/<targetArch>/[libdiroffs]/module.dep" + */ fprintf(stderr, "Dependency file %s not found\n", filename); } else { checkdep: @@ -1357,12 +1369,12 @@ static int require_priv( if (!(TRY_FILE(libdiroffs, PREFIX "%s" INFIX "%s%n" EXT, module, versionstr, &extoffs))) { - /* filename = - "<dirname>/[dirlen]<module>/<version>/R<epicsRelease>/[releasediroffs]/lib/<targetArch>/[libdiroffs]/PREFIX<module>INFIX[extoffs](EXT)?" - */ - /* or (old) - "<dirname>/[dirlen][releasediroffs][libdiroffs]PREFIX<module>INFIX(-<version>)?[extoffs](EXT)?" - */ + /* filename = + "<dirname>/[dirlen]<module>/<version>/R<epicsRelease>/[releasediroffs]/lib/<targetArch>/[libdiroffs]/PREFIX<module>INFIX[extoffs](EXT)?" + */ + /* or (old) + "<dirname>/[dirlen][releasediroffs][libdiroffs]PREFIX<module>INFIX(-<version>)?[extoffs](EXT)?" + */ printf("Module %s has no library\n", module); } else { loadlib: @@ -1447,9 +1459,9 @@ static int require_priv( putenvprintf("TEMPLATES=%s", globalTemplates); } + /* no need to execute startup script twice if not with new arguments */ if (loaded && args == NULL) { - return 0; /* no need to execute startup script twice if not with new - arguments */ + return 0; } return status;