Date: Mon, 31 Oct 2005 15:42:54 +0300 From: Igor Robul <igorr@speechpro.com> To: Rob <spamrefuse@yahoo.com>, freebsd-questions@freebsd.org Subject: dlopen()/dlsym()/dlerror() was: Re: libXcursor.so.1.0.2 reference in libX11.so.6 ?? Message-ID: <4366114E.2060907@speechpro.com> In-Reply-To: <20051031114230.57427.qmail@web36212.mail.mud.yahoo.com> References: <20051031114230.57427.qmail@web36212.mail.mud.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4366114E.2060907>