From 67bf9979c94ac7fe8893eac9a6703954af568759 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Mon, 12 Oct 2015 13:28:30 +0200 Subject: [PATCH] run a script on every module load to add version records --- moduleversion.template | 5 +++++ postModuleLoad.cmd | 1 + require.c | 29 +++++++++++++++++++++++++++++ require.h | 2 ++ 4 files changed, 37 insertions(+) create mode 100644 moduleversion.template create mode 100644 postModuleLoad.cmd diff --git a/moduleversion.template b/moduleversion.template new file mode 100644 index 0000000..f9fdf0a --- /dev/null +++ b/moduleversion.template @@ -0,0 +1,5 @@ +record (stringin, "$(IOC):$(MODULE)_VERSION") +{ + field (VAL, "$(VERSION)") + field (PINI, "YES") +} diff --git a/postModuleLoad.cmd b/postModuleLoad.cmd new file mode 100644 index 0000000..0b2e258 --- /dev/null +++ b/postModuleLoad.cmd @@ -0,0 +1 @@ +dbLoadRecords("moduleversion.template","IOC=$(IOC),MODULE=$(MODULE),VERSION=$($(MODULE)_VERSION)" diff --git a/require.c b/require.c index ec78f8d..2be3631 100644 --- a/require.c +++ b/require.c @@ -250,6 +250,20 @@ static int putenvprintf(const char* format, ...) return 0; } +static int runLoadScript(const char* script, const char* module, const char* version) +{ + char *scriptpath = NULL; + char *subst = NULL; + const char *mylocation = getLibLocation("require"); + if (!mylocation) return -1; + if (asprintf(&scriptpath, "%s/%s", mylocation, script) < 0) return -1; + if (asprintf(&subst, "MODULE=%s,VERSION=%s", module, version) < 0) return -1; + runScript(scriptpath, subst); + free(subst); + free(scriptpath); + return 0; +} + static void registerModule(const char* module, const char* version, const char* location) { moduleitem* m; @@ -272,6 +286,15 @@ static void registerModule(const char* module, const char* version, const char* loadedModules = m; putenvprintf("%s_VERSION=%s", module, version); putenvprintf("%s_DIR=%s", module, location); + + /* only do registration register stuff at init */ + if (interruptAccept) return; + + if (runLoadScript("postModuleLoad.cmd", module, version) < 0) + { + fprintf(stderr, "require: out of memory\n"); + return; + } } #if defined (vxWorks) @@ -775,6 +798,12 @@ int runScript(const char* filename, const char* args) long line_exp_size = line_raw_size; char** pairs; int status = 0; + + if (interruptAccept) + { + fprintf(stderr, "Warning: running %s\n", filename); + fprintf(stderr, "Warning: running scripts after iocInit may crash the ioc.\n"); + } pairs = (char*[]){ "", "environ", NULL, NULL }; diff --git a/require.h b/require.h index 10ad018..2a619ea 100644 --- a/require.h +++ b/require.h @@ -7,7 +7,9 @@ extern "C" { int require(const char* libname, const char* version, const char* args); const char* getLibVersion(const char* libname); +const char* getLibLocation(const char* libname); int libversionShow(const char* pattern, int showLocation); +int runScript(const char* filename, const char* args); #ifdef __cplusplus }