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

save and restore MODULE and MODULE_DIR after running a script, because that...

save and restore MODULE and MODULE_DIR after running a script, because that script may have called require
parent 9652c8df
No related branches found
No related tags found
No related merge requests found
......@@ -638,6 +638,7 @@ void registerModule(const char* module, const char* version, const char* locatio
putenvprintf("%s_VERSION=%s", module, version);
if (location)
{
putenvprintf("MODULE_DIR=%s", m->content+lm+lv);
putenvprintf("%s_DIR=%s", module, m->content+lm+lv);
pathAdd("SCRIPT_PATH", m->content+lm+lv);
}
......
......@@ -50,6 +50,9 @@ epicsShareFunc int epicsShareAPI iocshCmd(const char *cmd);
#include "expr.h"
#include "require.h"
#define SAVEENV(var) do { old_##var = getenv(#var); if (old_##var) old_##var=strdup(old_##var); } while(0)
#define RESTOREENV(var) do { if(old_##var) { putenvprintf("%s=%s", #var, old_##var); free(old_##var); }} while(0)
int runScriptDebug=0;
int runScript(const char* filename, const char* args)
......@@ -63,6 +66,8 @@ int runScript(const char* filename, const char* args)
long len;
char** pairs;
int status = 0;
char* old_MODULE = NULL;
char* old_MODULE_DIR = NULL;
if (!filename)
{
......@@ -161,8 +166,12 @@ int runScript(const char* filename, const char* args)
}
}
if (file == NULL) { perror(filename); return errno; }
/* save some environments variables */
SAVEENV(MODULE);
SAVEENV(MODULE_DIR);
/* line by line after expanding macros with arguments or environment */
/* execute script line by line after expanding macros with arguments or environment */
while (fgets(line_raw, line_raw_size, file))
{
char* p, *x;
......@@ -246,6 +255,11 @@ end:
free(line_exp);
if (mac) macDeleteHandle(mac);
if (file) fclose(file);
/* restore environment */
RESTOREENV(MODULE);
RESTOREENV(MODULE_DIR);
return status;
}
......
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