/
app.c
91 lines (79 loc) · 2.11 KB
/
app.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
84
85
86
87
88
89
90
91
#include "app.h"
#include "hiredis/hiredis.h"
#include "tpl.h"
#include "notifier.h"
#include "module.h"
#include "list.h"
#include "error.h"
#include <signal.h>
#include <mysql/mysql.h>
int module_global_init(void){
ngx_pool_t *pool;
ngx_log_t *log;
pool = ngx_create_pool(4096, log);
if (pool == NULL){
app_close(1);
printf("Error while creating pool buffer!");
return -1;
}
globals_r.pool = pool;
globals_r.log = log;
return 0;
}
/*
int module_global_init(void){
triger_set(NOTIFIER_INIT, 0, global_init);
return 0;
}*/
unsigned int app_init(){
signal(SIGHUP, app_close);
signal(SIGUSR1, app_close);
signal(SIGTERM, app_close);
signal(SIGCHLD, app_close);
notifier_chain_init();
module_init();
int ret = triger( NOTIFIER_INIT, &globals_r );
if((ret & NOTIFY_STOP) == NOTIFY_STOP) exit(STONE_ERROR_INIT); //init_error
// init_handlers(globals_r.pool);
}
void app_close(int num){
triger ( NOTIFIER_EXIT, &globals_r);
//extern struct GLOBAL_RAPHTERS globals_r;
//cleanup_handlers(globals_r.pool);
// should free the total memory
if ( globals_r.pool ) ngx_destroy_pool(globals_r.pool);
// globals_r.pool = NULL;
// globals_r.con = NULL;
}
stone_server_t * stone_app_start(struct thread_info_t *threadInfo, struct FCGX_Request *fcgx){
ngx_pool_t *pool;
stone_server_t *server;
stone_request_t *req;
stone_response_t *res;
tpl_data_table *tpl_data;
int rc;
//create pool first
pool = ngx_create_pool(4096, globals_r.log);
if (pool == NULL){
error_handler("Error while creating pool buffer!", fcgx);
return NULL;
}
//create server struct
server = ngx_palloc(pool, sizeof(stone_server_t));
if (server == NULL){
error_handler("Error while initializing server info!", fcgx);
return NULL;
}
server->pool = pool;
server->thread = threadInfo;
server->fcgx = fcgx;
server->async = 0; //no async caller
triger ( NOTIFIER_START, server );
// create request and response
return server;
}
int stone_app_stop(stone_server_t *server){
triger ( NOTIFIER_STOP, server );
ngx_destroy_pool(server->pool);
return 0;
}