views:

556

answers:

4

I am trying to write a program that allows a binary to be run, substituting a certain file when requested with another. It is a library with simple replacements for the system call functions, that is used with LD_PRELOAD. The problem is that it catches opens for reading (the substitute file is read instead), but writes always go back to the actual, specified file. Are there any other "open" system calls I should know about?

+1  A: 

I am not sure what the cause of your problem is, but using strace on your program might give some insight. It should be part of any sane Linux distribution.

rodion
A: 

substituting a certain file when requested with another

Sounds like you check only for the input file (do you check by filename?). You need to check and substitute the output file, too.

If you output goes to one of the standard outputs, then you need to close and reopen them with your output substitute) before you fork into the executable.

To find all system calls that your executable makes you can use strace.
To find all library calls that your executable makes you can use ltrace.

lothar
+1  A: 

If it's open for writing, it's most likely going through the creat function (I'm guessing fopen would be redirecting you there). Check your fcntl.h for a complete list.

eduffy
+3  A: 

Nevermind -- stupid mistake.

Wasn't checking both absolute and relative paths...

c4757p
+1 for finding it on your own
lothar