Hi,

Am Dienstag, 28. November 2006 10:09 schrieb Daniel-Constantin Mierla:
> to optimize a bit, I would keep the default flags in a variable and I
> will check the flags forced by a module with those ones, not to
> close/open again with same flags.

ACK. See attached patch.

> Also, maybe a value (like 0) should be 
> used to signal that the module wants to be loaded with the default flags
> and not double-check again.

I used "if (modflags >= 0)" (i.e.: -1 is "default flags"); 0 could potentially 
be a valid flag.

Thx a lot,
   Bastian

-- 
Collax GmbH . Burkheimer Straße 3 . 79111 Freiburg . Germany
p: +49 (0) 761-45684-24
f: +49 (0) 761-45684-10        www.collax.com

\ An unbreakable toy is useful for breaking other toys.
Index: sr_module.h
===================================================================
RCS file: /cvsroot/openser/sip-server/sr_module.h,v
retrieving revision 1.8
diff -u -r1.8 sr_module.h
--- sr_module.h	23 Nov 2006 21:57:14 -0000	1.8
+++ sr_module.h	28 Nov 2006 09:28:28 -0000
@@ -159,5 +159,10 @@
  *  - returns >0 if ok, 0 to drop message
  */
 
+struct mod_info_ {
+	int dlopenflags;
+};
+
+typedef struct mod_info_ mod_info_t;
 
 #endif
Index: sr_module.c
===================================================================
RCS file: /cvsroot/openser/sip-server/sr_module.c,v
retrieving revision 1.7
diff -u -r1.7 sr_module.c
--- sr_module.c	23 Nov 2006 21:57:13 -0000	1.7
+++ sr_module.c	28 Nov 2006 09:28:28 -0000
@@ -199,17 +199,40 @@
 	char* error;
 	struct module_exports* exp;
 	struct sr_module* t;
+	mod_info_t *info;
+	int defaultflags;
+	int modflags;
 	
 #ifndef RTLD_NOW
 /* for openbsd */
 #define RTLD_NOW DL_LAZY
 #endif
-	handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */
+	defaultflags = RTLD_NOW;
+	handle=dlopen(path, defaultflags); /* resolve all symbols now */
 	if (handle==0){
 		LOG(L_ERR, "ERROR: load_module: could not open module <%s>: %s\n",
 					path, dlerror() );
 		goto error;
 	}
+
+	dlerror();
+	if ((info = dlsym(handle, "mod_info"))) {	/* mod_info found */
+		if (!dlerror()) {			/* ... and no error occured */
+			modflags = info->dlopenflags;
+			if ((modflags != defaultflags) && (modflags >= 0)) {
+				dlclose(handle);
+				DBG("DEBUG:load_module:Reloading module %s with flags %d\n",
+					 path, modflags);
+				handle = dlopen(path, modflags);
+				if (handle==0){
+					LOG(L_ERR, "ERROR: load_module: could not open module <%s>: %s\n",
+								path, dlerror() );
+					goto error;
+				}
+			}
+
+		}
+	}
 	
 	for(t=modules;t; t=t->next){
 		if (t->handle==handle){
_______________________________________________
Devel mailing list
[email protected]
http://openser.org/cgi-bin/mailman/listinfo/devel

Reply via email to