Operating System - HP-UX
1753428 Members
4959 Online
108793 Solutions
New Discussion юеВ

HP-UX 11.11, C-ANSI-C: LD_PRELOAD fails

 
SOLVED
Go to solution
Olivier ROBERT
Frequent Advisor

HP-UX 11.11, C-ANSI-C: LD_PRELOAD fails

Dear forum readers,

I need to preload a non-system shared library for some program execution, which I used to do on HP-UX 11.00 in the past and it worked like a charm but now it doesn't. I tried with a simple case (redefining gethostname() and trying it with the hostname command), and still no luck.

Here is what I did:
1) I wrote the following program, gethostname.c:
----- gethostname.c BEGIN -----
#include
#include

int gethostname(char *hostname, size_t size)
{
strncpy(hostname,"test",size);
return 0;
}
----- gethostname.c END -----

2) I compiled:
$ cc -b -o gethostname.sl gethostname.c

3) I ran:
$ LD_PRELOAD=/gethostname.sl hostname

4) It returned:

Instead of what I expected:
test

Tried with time() too, returning zero in the hope that the date command would return the start of the Epoch, no more luck. Tried by just putting an exit() into gethostname() in the hope that hostname would return nothing, didn't work. Tried to export LD_PRELOAD= before running the command. Carefully checked that the .sl is chmod 755.

I use HP-UX 11.11, and I compiled with the "HP C/ANSI C Compiler" (C-ANSI-C). Do you have any idea about why it does not work?

Thanks for your help!

Olivier ROBERT
2 REPLIES 2
James Murtagh
Honored Contributor
Solution

Re: HP-UX 11.11, C-ANSI-C: LD_PRELOAD fails

Hi Olivier,

The LD_PRELOAD functionality on 11i was supplied in the linker patch PHSS_22535. I installed the later, recommended version, PHSS_26560, and got the desired results from your program. I was seeing my hostname too before installing this, no reboot is necessary. To find your current version use :

# swlist -l product|grep linker

Cheers,

James.
Olivier ROBERT
Frequent Advisor

Re: HP-UX 11.11, C-ANSI-C: LD_PRELOAD fails

Thanks James, it worked perfectly!

Olivier