diff options
Diffstat (limited to 'src/hook_lib/file_hook.c')
-rw-r--r-- | src/hook_lib/file_hook.c | 15 |
1 files changed, 13 insertions, 2 deletions
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 |