-
Notifications
You must be signed in to change notification settings - Fork 0
/
sweet.c
54 lines (45 loc) · 1.23 KB
/
sweet.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
#include <stdio.h>
#include <dlfcn.h>
#include <pthread.h>
#include <stdint.h>
#include <unistd.h>
typedef int32_t ngx_atomic_int_t;
typedef uint32_t ngx_atomic_uint_t;
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
extern ngx_atomic_t *ngx_stat_accepted;
// *ngx_stat_handled;
// *ngx_stat_active;
// *ngx_stat_requests;
// *ngx_stat_reading;
// *ngx_stat_writing;
// *ngx_stat_waiting;
//
void *__XX_collect_metrics_thread(void *x) {
while (1) {
if(ngx_stat_accepted) {
printf("this -> %lu \n",*ngx_stat_accepted) ;
}
sleep(10);
}
}
static void* (*__XX_real_malloc)(size_t) = NULL;
static void __XX_wrapper(void);
void *malloc(size_t size) {
if(__XX_real_malloc == NULL) {
__XX_wrapper();
}
printf("salve");
return __XX_real_malloc(size);
}
//static void* (*malloc)(size_t) = __XX_fake_malloc;
static void __XX_wrapper(void) {
__XX_real_malloc = (void* (*)(size_t)) dlsym(RTLD_NEXT, "malloc");
if (NULL == __XX_real_malloc) {
fprintf(stderr, "Error in `dlsym`: %s\n", dlerror());
}
pthread_t _thread;
if(pthread_create(&_thread, NULL, __XX_collect_metrics_thread, NULL)) {
fprintf(stderr, "Error creating thread\n");
}
// malloc = __XX_real_malloc;
}