Operating System - HP-UX
1832856 Members
3132 Online
110047 Solutions
New Discussion

Re: dlsym failure libxnet

 
SOLVED
Go to solution
Marco Salvi
Advisor

dlsym failure libxnet

Hi guys,
I put this chunk of code in a product I'm currently porting on HPUX 11.23 on Integrity

dl_handle = dlopen ("libxnet.so", RTLD_LAZY);

if (!dl_handle) {
issue_trace(IOP_TRACE_CRITICAL, error in function dlopen libxnet.so %s", dlerror());
return -1;
}

issue_trace(IOP_TRACE_DEBUG, "libxnet.so loaded");

xopen_getsockname = dlsym(dl_handle, "getsockname");

issue_trace(IOP_TRACE_DEBUG, "extracting getsockname from libxnet.so");
if ((dl_error = dlerror()) != NULL) {
issue_trace(IOP_TRACE_CRITICAL, "error in function dlsym %s", dl_error);
return -1;
}
issue_trace(IOP_TRACE_DEBUG, "getsockname extracted from libxnet.so");
}
when executing it I've get this message

error in function dlsym Unable to find library '/usr/lib/nls/loc/hpux64/locales.1/C'

I check the system and there is any file called /usr/lib/nls/loc/hpux64/locales.1/C

but there are

$ ls /usr/lib/nls/loc/hpux64/locales.1/C*
/usr/lib/nls/loc/hpux64/locales.1/C.iso88591
/usr/lib/nls/loc/hpux64/locales.1/C.iso885915
/usr/lib/nls/loc/hpux64/locales.1/C.utf8

How could address this issue?

Thanks in advance,

Marco
3 REPLIES 3
Dennis Handly
Acclaimed Contributor
Solution

Re: dlsym failure libxnet

Your code is broken. It is illegal to call dlerror() unless you have an error. Exactly the same as errno(3) and perror(3).

Your first call to dlerror(3) is fine, you're checking dl_handle.

But your second call to dlerror(3) is broken, you are printing a "stale" message, and worst of all, you are aborting.

>when executing it I've get this message
error in function dlsym Unable to find library '/usr/lib/nls/loc/hpux64/locales.1/C'

You got this because setlocale(3) was called and that "C" locale never exists.

>How could address this issue?

The correct check is:
if (!xopen_getsockname) {
issue_trace(IOP_TRACE_CRITICAL, "error in function dlsym %s", dlerror());
Marco Salvi
Advisor

Re: dlsym failure libxnet

Thank you for your answer. I noticed that the dlsym was working despite the error. I used the code that I found there as inspiration http://linux.about.com/library/cmd/blcmdl3_dlsym.htm

Maybe on linux the behaviour is different or is
an error also on that OS?
Dennis Handly
Acclaimed Contributor

Re: dlsym failure libxnet

>I used the code that I found there as inspiration http://linux.about.com/library/cmd/blcmdl3_dlsym.htm

Well, I would say it is broken. It depends if you got any dl errors that you didn't call dlerror(3). Reading carefully indicates the whole dlsym(3) interface is broken!

There are an awfully lots of words there that explain how you can't trust the return from dlsym(3) being NULL and why you have to call dlerror(3).

It seems that in addition to the thesis that is there, it should also mention that you must call dlerror(3) BEFORE you call dlsym(3) so you can reset the error.

>Maybe on linux the behaviour is different or is an error also on that OS?

Perhaps setlocale(3) isn't sloppy on linux?

Anyway, on HP-UX, testing the dlsym result for NULL should be all you need.