dlopen()/dlsym()/dlerror() was: Re: libXcursor.so.1.0.2 reference in libX11.so.6 ??

Igor Robul igorr at speechpro.com
Mon Oct 31 04:43:13 PST 2005


Rob wrote:

>>
>>So you can see, from where we got 1.0.2
>>
>>    
>>
>
>
>Yes, indeed, very true.
>It's Xorg that has this library version hardcoded.
>
>Meanwhile, I also found out following:
>
>On FreeBSD, the dl* functions do not reset a
>previous error indicator. In this specific case,
>in xc/lib/X11/CrGlCur.c Xorg will first try to
>"dlopen" the library libXcursor.so.1.0.2 without
>success (this will set the dlerror indicator),
>next Xorg will try to dlopen libXcursor.so.1.0
>without success (again sets dlerror indicator), but
>eventually successfully dlopens libXcursor.so.1.
>However, the last successful dlopen call does NOT
>clear the earlier dlerror indicator.
>  
>
dlerror() resets error indicator. From /usr/src/libexec/rtld-elf/rtld.c:

const char *
dlerror(void)
{
    char *msg = error_message;
    error_message = NULL;
    return msg;
}


Error indicator is not reseted by successful call to dlopen(), but I'm 
not sure that dlopen() need reset error
indicator. At least I could not find information about this in manual page.

>Conclusively:
>The whole library problem boils down to the
>behaviour of the dl* functions, with respect to
>the clearing/setting the dlerror indicator.
>In general, one should always call dlerror() prior
>to the use of the dl* functions, to clear any
>previous dlerror indicator:
>
>   dlerror(); /* clear previous error*/
>
>   handle = dlopen("blabla.lib", RTLD_LAZY)
>   if ( !handle ) {
>      error_print(dlerror());
>      return FAILURE;
>   }
>
>   data = dlsym(....);
>   error = dlerror();
>   if ( !data && error != NULL ) {
>      error_print(error);
>      return FAILURE;
>   }
>
>   etc. etc.
>
>Note that a dlerror() call always will clear any
>previous dlerror indicator.
>
>Does all that make sense to you?
>  
>
Yes.
Is there any standart which describes dl*() functions? Because from _my_ 
point of view
dlopen()/dlsym() need not clear error indicator on success, 
dlopen()/dlsym() need to return NULL
on error. dlerror() is one who can/have to clear error indicator.




More information about the freebsd-questions mailing list