[Devel] dlopen(... RTLD_LOCAL vs. RTLD_GLOBAL

Daniel-Constantin Mierla daniel at voice-system.ro
Tue Nov 28 10:09:11 CET 2006


Hello,

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. 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.

Cheers,
Daniel


On 11/28/06 10:58, Bastian Friedrich wrote:
> Hi,
>
> Am Montag, 27. November 2006 18:24 schrieb Bogdan-Andrei Iancu:
>   
>> I think we should go for the "best, but more difficult" option - how a
>> module is to be load must be 100% transparent for the user, so this
>> information should not reside in script, but in the module interface.
>>     
>
> ACK.
>
>   
>> let's have a new field in the interface saying how the module should be
>> load - if set to RTLD_GLOBAL, the module will be accordingly reloaded.
>>     
>
> I'm attaching a patch. It creates a new struct "mod_info" in the modules. 
> Uppon loading a module, the symbol is looked up. If it does not exist, 
> everything remains as it was; if it _does_ exist, it's currently single 
> element dlopenflags is used for a second dlopen call.
>
> Please tell me if this is approximately what you'd like.
>
> Thx,
>    Bastian
>
>   
> ------------------------------------------------------------------------
>
> 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 08:49:33 -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 08:49:33 -0000
> @@ -199,6 +199,8 @@
>  	char* error;
>  	struct module_exports* exp;
>  	struct sr_module* t;
> +	mod_info_t *info;
> +	int flags;
>  	
>  #ifndef RTLD_NOW
>  /* for openbsd */
> @@ -210,6 +212,22 @@
>  					path, dlerror() );
>  		goto error;
>  	}
> +
> +	dlerror();
> +	if ((info = dlsym(handle, "mod_info"))) {	/* mod_info found */
> +		if (!dlerror()) {			/* ... and no error occured */
> +			flags = info->dlopenflags;
> +			dlclose(handle);
> +			DBG("DEBUG:load_module:Reloading module %s with flags %d\n", path, flags);
> +			handle = dlopen(path, flags);
> +			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){
>   



More information about the Devel mailing list