LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-15-2010, 05:45 PM   #1
auli
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Rep: Reputation: 0
intercepting open() in Linux by shared library


Hi all,

I am writing a shared library to intercept calls to open() (partly inspired by how tsocks works). What I want to do is redirect tho open() to a different file (depending on the input pathname). So, I intend to intercept it, change pathname as required and then call the real open().

I tried doing this, but since I define open(), I can't call the real open(). To avoid this, I thought of using dlopen(). Please see the (very short) code I've written to do this.

http://pastie.org/826380

It gives the following error

'Inconsistency detected by ld.so: dl-open.c: 643: _dl_open: Assertion `_dl_debug_initialize (0, args.nsid)->r_state == RT_CONSISTENT' failed!'

Can you suggest a fix or an alternate way of doing this?


Thanks in advance!
auli
 
Old 02-15-2010, 06:25 PM   #2
auli
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Solved

Hi guys,

I was able to solve this problem.

The problem was that I needed to say
$ LD_PRELOAD=/lib/tls/i686/cmov/libdl.so.2:./libfile_io_intercept.so.1 open_example


Thanks,
auli

Edit:

Err.. It still doesn't work. I forgot that I had commented out my entire code when running :P

The error is generated at the "handle=dlopen();" line.

Last edited by auli; 02-15-2010 at 06:32 PM. Reason: false positive
 
Old 02-16-2010, 11:50 AM   #3
auli
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Original Poster
Rep: Reputation: 0
solved!

Solved by using RTLD_NEXT. Here is the code that works!

http://pastie.org/827447


auli
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shared library : libfg.so: cannot open shared object file error 40 x_gaurav Programming 2 06-28-2009 06:29 AM
ldd reports shared library missing, but library exists on disk athv_gr Linux - Newbie 7 05-13-2009 12:31 PM
gcc link shared library against another shared library qcp Linux - Newbie 1 07-25-2008 11:15 AM
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-04-2007 11:11 PM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration