Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Interpose system call 'open' using LD_PRELOAD does not work for 'open' called from within perl programs. Why?

by spartanwins (Initiate)
on Mar 10, 2008 at 05:13 UTC ( #673172=perlquestion: print w/ replies, xml ) Need Help??
spartanwins has asked for the wisdom of the Perl Monks concerning the following question:

Its regarding 'interposing' open system call and perl interaction.

I have a working code snippet which will interpose 'open' system call on Linux/Unix. But I am not able to trap 'open' calls made from within perl programs My interpose methos uses LD_PRELOAD and hence assumes that the applications are using dynamic linking...

  • does anyone know if perl 'open' uses static linking to OS 'open'?
  • is there any other way to interpose/ intercept 'open' calls invoked from pre-existing perl code and steer it to my code before giving control back to the real 'open'
I have studied ex::override to some degree, but could not figure out how I could interpose 'open' from pre-existing perl code

Comment on Interpose system call 'open' using LD_PRELOAD does not work for 'open' called from within perl programs. Why?
Re: Interpose system call 'open' using LD_PRELOAD does not work for 'open' called from within perl programs. Why?
by Corion (Pope) on Mar 10, 2008 at 07:13 UTC

    At some place, the perl executable has to enter in contact with the operating system and invoke its open (or fopen?) system call, so that is a place to wedge your code in.

    I don't know how your interception mechanism works, but if it tries to hand the program a fake libc instead of intercepting the system calls, you will run afoul of static linking. Whether your version of the perl executable uses static linking is another matter - Perl can be built to use static linking for some parts and dynamic linking for others. It may also well be that Perl uses some other call to open a file instead of open, but I don't know the C library well enough to suggest which other ones to intercept.

    If you stay within Perl, you can always override GLOBAL::open, from C or from Perl. If you want to install this universally, put it in a Perl module and preload that module via the PERL5OPTS environment variable.

Re: Interpose system call 'open' using LD_PRELOAD does not work for 'open' called from within perl programs. Why?
by ysth (Canon) on Mar 10, 2008 at 08:03 UTC
    I'm guessing the the actual open call you need to intercept is in libperl.so.5.8.8. Maybe loading that and then your intercept library in LD_PRELOAD would help? Not something I know a lot about.
Re: Interpose system call 'open' using LD_PRELOAD does not work for 'open' called from within perl programs. Why?
by kyle (Abbot) on Mar 10, 2008 at 17:46 UTC

    What's the XY Problem here? What are you really trying to accomplish? What do you have, and what are you trying to get? Perhaps there is a better way than trying to replace open.

Re: Interpose system call 'open' using LD_PRELOAD does not work for 'open' called from within perl programs. Why?
by pc88mxer (Vicar) on Mar 10, 2008 at 19:57 UTC
    Update: Figured it out. You need to intercept open64, not open.

    Previously I wrote:

    This is interesting. I can intercept other functions like getpid and close, but there's something different about open.

    I'd ask the perl5-porters mailing list - I'm sure someone there would know what's going on.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://673172]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-08-23 04:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls