Преглед на файлове

module version checking introduced

Jiri Kuthan преди 22 години
родител
ревизия
2dcb8b679b
променени са 3 файла, в които са добавени 33 реда и са изтрити 4 реда
  1. 2 0
      modules/tm/tm.c
  2. 29 4
      sr_module.c
  3. 2 0
      sr_module.h

+ 2 - 0
modules/tm/tm.c

@@ -94,6 +94,8 @@
 #include "t_lookup.h"
 #include "t_stats.h"
 
+MODULE_VERSION
+
 
 
 inline static int w_t_check(struct sip_msg* msg, char* str, char* str2);

+ 29 - 4
sr_module.c

@@ -31,6 +31,7 @@
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  *  2003-03-19  Support for flags in find_export (janakj)
  *  2003-03-29  cleaning pkg_mallocs introduced (jiri)
+ *  2003-04-24  module version checking introduced (jiri)
  */
 
 
@@ -147,6 +148,32 @@ error:
 	return ret;
 }
 
+#ifndef DLSYM_PREFIX
+/* define it to null */
+#define DLSYM_PREFIX
+#endif
+
+static inline int version_control(void *handle, char *path)
+{
+	char **m_ver;
+	char* error;
+
+	m_ver=(char **)dlsym(handle, DLSYM_PREFIX "module_version");
+	if ((error=(char *)dlerror())!=0) {
+		LOG(L_WARN, "WARNING: no version info in module <%s>: %s\n",
+			path, error );
+		return 0;
+	}
+	if (!m_ver || !(*m_ver)) {
+		LOG(L_WARN, "WARNING: no version in module <%s>\n", path );
+		return 0;
+	}
+	if (strcmp(VERSION,*m_ver)==0)
+		return 1;
+	LOG(L_WARN, "WARNING: module version mismatch for %s; "
+		"core: %s; module: %s\n", path, VERSION, *m_ver );
+	return 0;
+}
 
 /* returns 0 on success , <0 on error */
 int load_module(char* path)
@@ -159,10 +186,6 @@ int load_module(char* path)
 #ifndef RTLD_NOW
 /* for openbsd */
 #define RTLD_NOW DL_LAZY
-#endif
-#ifndef DLSYM_PREFIX
-/* define it to null */
-#define DLSYM_PREFIX
 #endif
 	handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */
 	if (handle==0){
@@ -178,6 +201,8 @@ int load_module(char* path)
 			goto skip;
 		}
 	}
+	/* version control */
+	version_control(handle, path);
 	/* launch register */
 	exp = (struct module_exports*)dlsym(handle, DLSYM_PREFIX "exports");
 	if ( (error =(char*)dlerror())!=0 ){

+ 2 - 0
sr_module.h

@@ -66,6 +66,8 @@ typedef enum {
 #define PROC_FIFO     -2  /* FIFO attendant process */
 #define PROC_TCP_MAIN -4  /* TCP main process */
 
+#define MODULE_VERSION char *module_version=VERSION;
+
 struct cmd_export_ {
 	char* name;             /* null terminated command name */
 	cmd_function function;  /* pointer to the corresponding function */