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?
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
2009-05-29 00:34:22
+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
2009-05-29 00:38:51
+3
A:
Nevermind -- stupid mistake.
Wasn't checking both absolute and relative paths...
c4757p
2009-05-29 01:08:36
+1 for finding it on your own
lothar
2009-05-29 01:14:11