-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlibtest.c
83 lines (71 loc) · 1.98 KB
/
libtest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <stdio.h>
#include <dlfcn.h>
#include <unistd.h>
volatile int governor_get_command = 0;
int (*connect_to_server)() = NULL;
int (*send_info_begin)(char *) = NULL;
int (*send_info_end)(char *) = NULL;
int (*close_sock)() = NULL;
void * governor_library_handle = NULL;
int main(){
governor_get_command = 1;
connect_to_server = NULL;
send_info_begin = NULL;
send_info_end = NULL;
close_sock = NULL;
governor_library_handle = NULL;
char *error_dl = NULL;
governor_library_handle = dlopen("/root/msql/governor-new/lib/libgovernor.so", RTLD_LAZY);
if (governor_library_handle) {
while(1){
connect_to_server = (int (*)())dlsym(governor_library_handle, "connect_to_server");
if ((error_dl = dlerror()) != NULL){
connect_to_server = NULL;
send_info_begin = NULL;
send_info_end = NULL;
close_sock = NULL;
break;
}
send_info_begin = (int (*)(char *))dlsym(governor_library_handle, "send_info_begin");
if ((error_dl = dlerror()) != NULL){
connect_to_server = NULL;
send_info_begin = NULL;
send_info_end = NULL;
close_sock = NULL;
break;
}
send_info_end = (int (*)(char *))dlsym(governor_library_handle, "send_info_end");
if ((error_dl = dlerror()) != NULL){
connect_to_server = NULL;
send_info_begin = NULL;
send_info_end = NULL;
close_sock = NULL;
break;
}
close_sock = (int (*)())dlsym(governor_library_handle, "close_sock");
if ((error_dl = dlerror()) != NULL){
connect_to_server = NULL;
send_info_begin = NULL;
send_info_end = NULL;
close_sock = NULL;
break;
}
break;
}
}
if(connect_to_server){
(*connect_to_server)();
}
if(send_info_begin&&governor_get_command){
(*send_info_begin)("test2");
}
printf("Ok\n");
sleep(10);
if(send_info_end&&governor_get_command){
(*send_info_end)("test2");
}
if(close_sock){
(*close_sock)();
}
return 0;
}