Browse code

module version checking introduced

Jiri Kuthan authored on 27/04/2003 18:17:23
Showing 3 changed files
... ...
@@ -94,6 +94,8 @@
94 94
 #include "t_lookup.h"
95 95
 #include "t_stats.h"
96 96
 
97
+MODULE_VERSION
98
+
97 99
 
98 100
 
99 101
 inline static int w_t_check(struct sip_msg* msg, char* str, char* str2);
... ...
@@ -31,6 +31,7 @@
31 31
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
32 32
  *  2003-03-19  Support for flags in find_export (janakj)
33 33
  *  2003-03-29  cleaning pkg_mallocs introduced (jiri)
34
+ *  2003-04-24  module version checking introduced (jiri)
34 35
  */
35 36
 
36 37
 
... ...
@@ -147,6 +148,32 @@ error:
147 147
 	return ret;
148 148
 }
149 149
 
150
+#ifndef DLSYM_PREFIX
151
+/* define it to null */
152
+#define DLSYM_PREFIX
153
+#endif
154
+
155
+static inline int version_control(void *handle, char *path)
156
+{
157
+	char **m_ver;
158
+	char* error;
159
+
160
+	m_ver=(char **)dlsym(handle, DLSYM_PREFIX "module_version");
161
+	if ((error=(char *)dlerror())!=0) {
162
+		LOG(L_WARN, "WARNING: no version info in module <%s>: %s\n",
163
+			path, error );
164
+		return 0;
165
+	}
166
+	if (!m_ver || !(*m_ver)) {
167
+		LOG(L_WARN, "WARNING: no version in module <%s>\n", path );
168
+		return 0;
169
+	}
170
+	if (strcmp(VERSION,*m_ver)==0)
171
+		return 1;
172
+	LOG(L_WARN, "WARNING: module version mismatch for %s; "
173
+		"core: %s; module: %s\n", path, VERSION, *m_ver );
174
+	return 0;
175
+}
150 176
 
151 177
 /* returns 0 on success , <0 on error */
152 178
 int load_module(char* path)
... ...
@@ -160,10 +187,6 @@ int load_module(char* path)
160 160
 /* for openbsd */
161 161
 #define RTLD_NOW DL_LAZY
162 162
 #endif
163
-#ifndef DLSYM_PREFIX
164
-/* define it to null */
165
-#define DLSYM_PREFIX
166
-#endif
167 163
 	handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */
168 164
 	if (handle==0){
169 165
 		LOG(L_ERR, "ERROR: load_module: could not open module <%s>: %s\n",
... ...
@@ -178,6 +201,8 @@ int load_module(char* path)
178 178
 			goto skip;
179 179
 		}
180 180
 	}
181
+	/* version control */
182
+	version_control(handle, path);
181 183
 	/* launch register */
182 184
 	exp = (struct module_exports*)dlsym(handle, DLSYM_PREFIX "exports");
183 185
 	if ( (error =(char*)dlerror())!=0 ){
... ...
@@ -66,6 +66,8 @@ typedef enum {
66 66
 #define PROC_FIFO     -2  /* FIFO attendant process */
67 67
 #define PROC_TCP_MAIN -4  /* TCP main process */
68 68
 
69
+#define MODULE_VERSION char *module_version=VERSION;
70
+
69 71
 struct cmd_export_ {
70 72
 	char* name;             /* null terminated command name */
71 73
 	cmd_function function;  /* pointer to the corresponding function */