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 148
 	return ret;
148 149
 }
149 150
 
151
+#ifndef DLSYM_PREFIX
152
+/* define it to null */
153
+#define DLSYM_PREFIX
154
+#endif
155
+
156
+static inline int version_control(void *handle, char *path)
157
+{
158
+	char **m_ver;
159
+	char* error;
160
+
161
+	m_ver=(char **)dlsym(handle, DLSYM_PREFIX "module_version");
162
+	if ((error=(char *)dlerror())!=0) {
163
+		LOG(L_WARN, "WARNING: no version info in module <%s>: %s\n",
164
+			path, error );
165
+		return 0;
166
+	}
167
+	if (!m_ver || !(*m_ver)) {
168
+		LOG(L_WARN, "WARNING: no version in module <%s>\n", path );
169
+		return 0;
170
+	}
171
+	if (strcmp(VERSION,*m_ver)==0)
172
+		return 1;
173
+	LOG(L_WARN, "WARNING: module version mismatch for %s; "
174
+		"core: %s; module: %s\n", path, VERSION, *m_ver );
175
+	return 0;
176
+}
150 177
 
151 178
 /* returns 0 on success , <0 on error */
152 179
 int load_module(char* path)
... ...
@@ -159,10 +186,6 @@ int load_module(char* path)
159 186
 #ifndef RTLD_NOW
160 187
 /* for openbsd */
161 188
 #define RTLD_NOW DL_LAZY
162
-#endif
163
-#ifndef DLSYM_PREFIX
164
-/* define it to null */
165
-#define DLSYM_PREFIX
166 189
 #endif
167 190
 	handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */
168 191
 	if (handle==0){
... ...
@@ -178,6 +201,8 @@ int load_module(char* path)
178 201
 			goto skip;
179 202
 		}
180 203
 	}
204
+	/* version control */
205
+	version_control(handle, path);
181 206
 	/* launch register */
182 207
 	exp = (struct module_exports*)dlsym(handle, DLSYM_PREFIX "exports");
183 208
 	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 */