Re: Replacing read() by a debugging function



"A. Farber" <Alexander.Farber@xxxxxxxxx> writes:
On Jan 28, 3:45 pm, fnegroni <f.e.negr...@xxxxxxxxxxxxxx> wrote:
And therefore function pointers achieve exactly the intended goal, bar
optimisation.

Hello fnegroni,

you have replied 3 times in my thread, thank you.

But I don't get your point. In the 1st reply you have
rephrased my original question and in the following
just written "look above".

So my question again: is there a way to replace
a syscall? I'm trying the following, but it doesn't work:

4DEL03468:~ {542} cat replace-write.c
#include <stdio.h>
#include <unistd.h>

ssize_t write2(int d, const void *buf, size_t nbytes) {
fprintf(stderr, "ok, replaced\n");
}

int main(int argc, char *argv[]) {
write = write2;
write(STDERR_FILENO, "blah\n", 5);
}

4DEL03468:~ {543} gcc replace-write.c -o replace-write.exe
replace-write.c: In function `main':
replace-write.c:9: error: invalid lvalue in assignment

And yes Eric, I haven't measured yet how much does
an "if(debug)" last (I probably can do it with gprof?)
but I'm sure it takes more than nothing, esp. in a loop.

Regards
Alex

Traditionally system calls have been defined 'weak' such that
they can be overridden by an application. Thus, you simply define
your own 'read' function, and internally call either "_read" or
perhaps "pread" to get the real system call functionality.

scott
.