1 |
commit: b6e44ffc06122453c92801d39d08f3c6ebc3ba14 |
2 |
Author: Alexander Bersenev <bay <AT> hackerdom <DOT> ru> |
3 |
AuthorDate: Sat Sep 24 01:51:28 2011 +0000 |
4 |
Commit: Александр Берсенев <bay <AT> hackerdom <DOT> ru> |
5 |
CommitDate: Sat Sep 24 01:51:28 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=b6e44ffc |
7 |
|
8 |
fixes bug with pmake. Use libc\'s snprintf |
9 |
|
10 |
--- |
11 |
src/hook_lib/Makefile | 2 +- |
12 |
src/hook_lib/file_hook.c | 15 +++++++++++++-- |
13 |
2 files changed, 14 insertions(+), 3 deletions(-) |
14 |
|
15 |
diff --git a/src/hook_lib/Makefile b/src/hook_lib/Makefile |
16 |
index 365ceee..2457fb2 100644 |
17 |
--- a/src/hook_lib/Makefile |
18 |
+++ b/src/hook_lib/Makefile |
19 |
@@ -2,7 +2,7 @@ file_hook.so: file_hook.o |
20 |
ld -shared -o file_hook.so -ldl -lc file_hook.o |
21 |
|
22 |
file_hook.o: file_hook.c |
23 |
- cc -Wall -fPIC -o file_hook.o -c file_hook.c |
24 |
+ cc -Wall -O0 -fPIC -o file_hook.o -c file_hook.c |
25 |
|
26 |
all: file_hook.so |
27 |
|
28 |
|
29 |
diff --git a/src/hook_lib/file_hook.c b/src/hook_lib/file_hook.c |
30 |
index 9e9bddc..5630581 100644 |
31 |
--- a/src/hook_lib/file_hook.c |
32 |
+++ b/src/hook_lib/file_hook.c |
33 |
@@ -79,6 +79,12 @@ pid_t (*_fork)(); |
34 |
int (*_setenv)(const char *name, const char *value, int overwrite); |
35 |
int (*_close)(int fd); // we hooking this, because some programs closes our socket |
36 |
|
37 |
+// we not hook this functions but we should be sure that these functions |
38 |
+// are from glibc |
39 |
+ |
40 |
+int (*_snprintf)(char *str, size_t size, const char *format, ...); |
41 |
+ |
42 |
+ |
43 |
int is_initialized=0; // when init not lauched yet we should no do any actions |
44 |
|
45 |
int log_socket=-1; |
46 |
@@ -159,6 +165,7 @@ void __init_hooks() { |
47 |
_setenv=(int (*)(const char *name, const char *value, int overwrite)) dlsym(RTLD_NEXT, "setenv"); |
48 |
_close= (int (*)(int fd)) dlsym(RTLD_NEXT, "close"); |
49 |
|
50 |
+ _snprintf=(int (*)(char *str, size_t size, const char *format, ...)) dlsym(RTLD_NEXT, "snprintf"); |
51 |
|
52 |
if(_open==NULL || _open64==NULL || |
53 |
_fopen==NULL || _fopen64==NULL || |
54 |
@@ -233,16 +240,20 @@ static int __raw_log_event(const char *event_type, const char *filename, char *r |
55 |
char msg_buff[MAXSOCKETMSGLEN]; |
56 |
int bytes_to_send; |
57 |
if(strcmp(result,"ERR")==0) { |
58 |
- bytes_to_send=snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s/%d", |
59 |
+ bytes_to_send=_snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s/%d", |
60 |
(unsigned long long)time(NULL),0,event_type,0,filename,0,stage,0,result,err); |
61 |
} else { |
62 |
- bytes_to_send=snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s", |
63 |
+ bytes_to_send=_snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s", |
64 |
(unsigned long long)time(NULL),0,event_type,0,filename,0,stage,0,result); |
65 |
} |
66 |
|
67 |
if(bytes_to_send>=MAXSOCKETMSGLEN) |
68 |
return 0; |
69 |
|
70 |
+ // we need to recount bytes_to_send here because some programs |
71 |
+ // use hackish snprintf which returns strlen(buf) |
72 |
+ |
73 |
+ |
74 |
if(send(log_socket,msg_buff,bytes_to_send,0)==-1) { |
75 |
__doreconnect(); // looks like our socket has been destroyed by logged program |
76 |
// try to recreate it |