Skip to content
Snippets Groups Projects
Commit 46faa850 authored by Dirk Zimoch's avatar Dirk Zimoch
Browse files

environment variable changes: module_DB and module_VERSION new, TEMPLATES...

environment variable changes: module_DB and module_VERSION new, TEMPLATES restored when not used by module
parent 24d00bbf
No related branches found
No related tags found
No related merge requests found
...@@ -220,6 +220,36 @@ typedef struct moduleitem ...@@ -220,6 +220,36 @@ typedef struct moduleitem
moduleitem* loadedModules = NULL; moduleitem* loadedModules = NULL;
static int putenvprintf(const char* format, ...) __attribute__((format(printf,1,2)));
static int putenvprintf(const char* format, ...)
{
va_list ap;
char *var;
va_start(ap, format);
if (vasprintf(&var, format, ap) < 0)
{
perror("require putenv");
return errno;
}
va_end(ap);
if (requireDebug)
printf("require: putenv(\"%s\")\n", var);
putenv(var);
/* Why putenv()?
vxWorks has no setenv()
Epics 3.13 has no epicsEnvSet()
Do not free the memory given to putenv (except for vxWorks)!
*/
#ifdef vxWorks
free(var);
#endif
return 0;
}
static void registerModule(const char* module, const char* version, const char* location) static void registerModule(const char* module, const char* version, const char* location)
{ {
moduleitem* m; moduleitem* m;
...@@ -240,6 +270,8 @@ static void registerModule(const char* module, const char* version, const char* ...@@ -240,6 +270,8 @@ static void registerModule(const char* module, const char* version, const char*
strcpy (m->content+lm+lv, location ? location : ""); strcpy (m->content+lm+lv, location ? location : "");
m->next = loadedModules; m->next = loadedModules;
loadedModules = m; loadedModules = m;
putenvprintf("%s_VERSION=%s", module, version);
putenvprintf("%s_DIR=%s", module, location);
} }
#if defined (vxWorks) #if defined (vxWorks)
...@@ -325,8 +357,6 @@ static int findLibRelease ( ...@@ -325,8 +357,6 @@ static int findLibRelease (
static void registerExternalModules() static void registerExternalModules()
{ {
if (requireDebug)
printf("require: registerExternalModules()\n");
/* iterate over all loaded libraries */ /* iterate over all loaded libraries */
dl_iterate_phdr(findLibRelease, NULL); dl_iterate_phdr(findLibRelease, NULL);
} }
...@@ -543,29 +573,6 @@ static int compareVersions(const char* found, const char* request) ...@@ -543,29 +573,6 @@ static int compareVersions(const char* found, const char* request)
return HIGHER; return HIGHER;
} }
static int putenvprintf(const char* format, ...) __attribute__((format(printf,1,2)));
static int putenvprintf(const char* format, ...)
{
va_list ap;
char *var;
va_start(ap, format);
if (vasprintf(&var, format, ap) < 0)
{
perror("require putenv");
return errno;
}
va_end(ap);
if (requireDebug)
printf("require: putenv(\"%s\")\n", var);
putenv(var);
#ifdef vxWorks
free(var);
#endif
return 0;
}
/* require (module) /* require (module)
Look if module is already loaded. Look if module is already loaded.
If module is already loaded check for version mismatch. If module is already loaded check for version mismatch.
...@@ -878,6 +885,8 @@ static int require_priv(const char* module, const char* version, const char* arg ...@@ -878,6 +885,8 @@ static int require_priv(const char* module, const char* version, const char* arg
int someVersionFound = 0; int someVersionFound = 0;
int someArchFound = 0; int someArchFound = 0;
static char* globalTemplates = NULL;
if (requireDebug) if (requireDebug)
printf("require: module=\"%s\" version=\"%s\" args=\"%s\"\n", module, version, args); printf("require: module=\"%s\" version=\"%s\" args=\"%s\"\n", module, version, args);
...@@ -889,6 +898,12 @@ static int require_priv(const char* module, const char* version, const char* arg ...@@ -889,6 +898,12 @@ static int require_priv(const char* module, const char* version, const char* arg
(snprintf(filename + offs, sizeof(filename) - offs, args) && fileNotEmpty(filename)) (snprintf(filename + offs, sizeof(filename) - offs, args) && fileNotEmpty(filename))
driverpath = getenv("EPICS_DRIVER_PATH"); driverpath = getenv("EPICS_DRIVER_PATH");
if (!globalTemplates)
{
char *t = getenv("TEMPLATES");
if (t) globalTemplates = strdup(t);
}
if (driverpath == NULL) driverpath = "."; if (driverpath == NULL) driverpath = ".";
if (requireDebug) if (requireDebug)
printf("require: searchpath=%s\n", driverpath); printf("require: searchpath=%s\n", driverpath);
...@@ -1212,14 +1227,8 @@ loadlib: ...@@ -1212,14 +1227,8 @@ loadlib:
status = 0; status = 0;
/* set up environment */ /* set up environment */
/* Why putenv()?
vxWorks has no setenv()
Epics 3.13 has no epicsEnvSet()
Do not free the memory given to putenv (except for vxWorks)!
*/
putenvprintf("MODULE=%s", module); /* "<dirname>/<module>/<version>/R<epicsRelease>/" */ putenvprintf("MODULE=%s", module);
putenvprintf("%s_DIR=%s", module, filename);
if (requireDebug) if (requireDebug)
printf("require: looking for template directory\n"); printf("require: looking for template directory\n");
...@@ -1239,10 +1248,12 @@ loadlib: ...@@ -1239,10 +1248,12 @@ loadlib:
/* set up db search path environment variables /* set up db search path environment variables
<module>_TEMPLATES template path of <module> <module>_TEMPLATES template path of <module>
<module>_DB template path of <module>
TEMPLATES template path of the current module (overwritten) TEMPLATES template path of the current module (overwritten)
EPICS_DB_INCLUDE_PATH template path of all loaded modules (last in front after ".") EPICS_DB_INCLUDE_PATH template path of all loaded modules (last in front after ".")
*/ */
putenvprintf("%s_DB=%s", module, absdir);
putenvprintf("%s_TEMPLATES=%s", module, absdir); putenvprintf("%s_TEMPLATES=%s", module, absdir);
putenvprintf("TEMPLATES=%s", absdir); putenvprintf("TEMPLATES=%s", absdir);
...@@ -1282,7 +1293,10 @@ loadlib: ...@@ -1282,7 +1293,10 @@ loadlib:
} }
else else
{ {
putenvprintf("TEMPLATES=."); char *t;
t = getenv("TEMPLATES");
if (globalTemplates && (!t || strcmp(globalTemplates, t) != 0))
putenvprintf("TEMPLATES=%s", globalTemplates);
} }
#define SETUP_PATH(NAME, args...) \ #define SETUP_PATH(NAME, args...) \
......
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