Working on a project and I need to override fopen() function.I call it to another .c file including what is required and making a true makefile with setting LD_PRELOAD.In Eclipse IDE I have 2 errors "Symbol 'RTLD_NEXT' could not be resolved ".When I run it manually from terminal I dont get any error but seems like this fopen() doesn't replace the original. I prove this when I call a printf(" ") in my fopen() and don't see the result.
logger: logger.c
gcc -Wall -fPIC -shared -o logger.so logger.c -lcrypto -ldl
acmonitor: acmonitor.c
gcc acmonitor.c -o acmonitor
test_aclog: test_aclog.c
gcc test_aclog.c -o test_aclog
run: logger.so test_aclog
LD_PRELOAD=./logger.so ./test_aclog
clean:
rm -rf logger.so
rm -rf test_aclog
rm -rf acmonitor
fopen(const char *path, const char *mode)
{
printf("In our own fopen, opening %s\n", path);
FILE *original_fopen_ret;
FILE *(*original_fopen)(const char*, const char*);
/* call the original fopen function */
original_fopen = dlsym(RTLD_NEXT, "fopen");
original_fopen_ret = (*original_fopen)(path, mode);
/* */
/* ... */
/* ... */
/* ... */
/* ... */
return original_fopen_ret;
}