diff options
author | Alexander Bersenev <bay@hackerdom.ru> | 2011-09-24 01:51:28 +0000 |
---|---|---|
committer | Alexander Bersenev <bay@hackerdom.ru> | 2011-09-24 01:51:28 +0000 |
commit | b6e44ffc06122453c92801d39d08f3c6ebc3ba14 (patch) | |
tree | a905a1b3353c612b4809af6b233e487dfc1669b2 /src | |
parent | python3 fixes and indenting (diff) | |
download | autodep-b6e44ffc06122453c92801d39d08f3c6ebc3ba14.tar.gz autodep-b6e44ffc06122453c92801d39d08f3c6ebc3ba14.tar.bz2 autodep-b6e44ffc06122453c92801d39d08f3c6ebc3ba14.zip |
fixes bug with pmake. Use libc\'s snprintf
Diffstat (limited to 'src')
-rw-r--r-- | src/hook_lib/Makefile | 2 | ||||
-rw-r--r-- | src/hook_lib/file_hook.c | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/hook_lib/Makefile b/src/hook_lib/Makefile index 365ceee..2457fb2 100644 --- a/src/hook_lib/Makefile +++ b/src/hook_lib/Makefile @@ -2,7 +2,7 @@ file_hook.so: file_hook.o ld -shared -o file_hook.so -ldl -lc file_hook.o file_hook.o: file_hook.c - cc -Wall -fPIC -o file_hook.o -c file_hook.c + cc -Wall -O0 -fPIC -o file_hook.o -c file_hook.c all: file_hook.so diff --git a/src/hook_lib/file_hook.c b/src/hook_lib/file_hook.c index 9e9bddc..5630581 100644 --- a/src/hook_lib/file_hook.c +++ b/src/hook_lib/file_hook.c @@ -79,6 +79,12 @@ pid_t (*_fork)(); int (*_setenv)(const char *name, const char *value, int overwrite); int (*_close)(int fd); // we hooking this, because some programs closes our socket +// we not hook this functions but we should be sure that these functions +// are from glibc + +int (*_snprintf)(char *str, size_t size, const char *format, ...); + + int is_initialized=0; // when init not lauched yet we should no do any actions int log_socket=-1; @@ -159,6 +165,7 @@ void __init_hooks() { _setenv=(int (*)(const char *name, const char *value, int overwrite)) dlsym(RTLD_NEXT, "setenv"); _close= (int (*)(int fd)) dlsym(RTLD_NEXT, "close"); + _snprintf=(int (*)(char *str, size_t size, const char *format, ...)) dlsym(RTLD_NEXT, "snprintf"); if(_open==NULL || _open64==NULL || _fopen==NULL || _fopen64==NULL || @@ -233,16 +240,20 @@ static int __raw_log_event(const char *event_type, const char *filename, char *r char msg_buff[MAXSOCKETMSGLEN]; int bytes_to_send; if(strcmp(result,"ERR")==0) { - bytes_to_send=snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s/%d", + bytes_to_send=_snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s/%d", (unsigned long long)time(NULL),0,event_type,0,filename,0,stage,0,result,err); } else { - bytes_to_send=snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s", + bytes_to_send=_snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s", (unsigned long long)time(NULL),0,event_type,0,filename,0,stage,0,result); } if(bytes_to_send>=MAXSOCKETMSGLEN) return 0; + // we need to recount bytes_to_send here because some programs + // use hackish snprintf which returns strlen(buf) + + if(send(log_socket,msg_buff,bytes_to_send,0)==-1) { __doreconnect(); // looks like our socket has been destroyed by logged program // try to recreate it |