Падает в строке 109 - при попытке достать конфу свою локальную. Признак падения - ничего не пишется в файл, а nginx на запрос молчит.
1 #include <ngx_config.h>
2 #include <ngx_core.h>
3 #include <ngx_http.h>
4 struct zzzxxx_stuff
5 {
6 int sd;
7 struct sockaddr_in server;
8 };
9 typedef struct
10 {
11 ngx_str_t testhost;
12 ngx_str_t multiply;
13 ngx_flag_t enable;
14 struct zzzxxx_stuff* stuff;
15 } ngx_http_zzzxxx_loc_conf_t;
16 typedef struct
17 {
18 ngx_http_upstream_conf_t upstream;
19 } xxxxngx_http_zzzxxx_loc_conf_t;
20 static ngx_int_t ngx_http_zzzxxx_module_init ( ngx_conf_t *cf );
21 static void* ngx_http_zzzxxx_create_loc_conf ( ngx_conf_t *cf );
22 static char* ngx_http_zzzxxx_merge_loc_conf (ngx_conf_t *cf, void *parent, void *child);
23 static ngx_int_t ngx_http_zzzxxx_module_handler ( ngx_http_request_t *r);
24 static ngx_command_t ngx_http_zzzxxx_commands[] =
25 {
26 {
27 ngx_string("zzzxxxmultiply"),
28 NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF| NGX_CONF_TAKE1,
29 ngx_conf_set_str_slot,
30 NGX_HTTP_LOC_CONF_OFFSET,
31 offsetof(ngx_http_zzzxxx_loc_conf_t, multiply),
32 NULL
33 },
34 {
35 ngx_string("zzzxxxtesthost"),
36 NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF| NGX_CONF_TAKE1,
37 ngx_conf_set_str_slot,
38 NGX_HTTP_LOC_CONF_OFFSET,
39 offsetof(ngx_http_zzzxxx_loc_conf_t, testhost),
40 NULL
41 },
42 ngx_null_command
43 };
44 static ngx_http_module_t ngx_http_zzzxxx_module_ctx =
45 {
46 NULL, /* preconfiguration */
47 ngx_http_zzzxxx_module_init, /* postconfiguration */
48 NULL, /* create main configuration */
49 NULL, /* init main configuration */
50 NULL, /* create server configuration */
51 NULL, /* merge server configuration */
52 ngx_http_zzzxxx_create_loc_conf, /* create location configuration */
53 ngx_http_zzzxxx_merge_loc_conf /* merge location configuration */
54 };
55 ngx_module_t ngx_http_zzzxxx_module =
56 {
57 NGX_MODULE_V1,
58 &ngx_http_zzzxxx_module_ctx, /* module context */
59 ngx_http_zzzxxx_commands, /* module directives */
60 NGX_HTTP_MODULE, /* module type */
61 NULL, /* init master */
62 NULL, /* init module */
63 NULL, /* init process */
64 NULL, /* init thread */
65 NULL, /* exit thread */
66 NULL, /* exit process */
67 NULL, /* exit master */
68 NGX_MODULE_V1_PADDING
69 };
70 static ngx_int_t ngx_http_zzzxxx_module_init ( ngx_conf_t *cf )
71 {
72 ngx_http_zzzxxx_loc_conf_t* c;
73 c = ngx_http_conf_get_module_loc_conf ( cf, ngx_http_zzzxxx_module );
74 ngx_http_handler_pt *h;
75 ngx_http_core_main_conf_t *cmcf;
76 cmcf = ngx_http_conf_get_module_main_conf ( cf, ngx_http_core_module );
77 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
78 if (h == NULL) {
79 return NGX_ERROR;
80 }
81 *h = ngx_http_zzzxxx_module_handler;
82 return NGX_OK;
83 }
84 static void* ngx_http_zzzxxx_create_loc_conf ( ngx_conf_t *cf )
85 {
86 ngx_http_zzzxxx_loc_conf_t* conf;
87 conf = ngx_pcalloc ( cf -> pool, sizeof ( ngx_http_zzzxxx_loc_conf_t ) );
88 if ( NULL == conf )
89 return NGX_CONF_ERROR;
90 return conf;
91 }
92 static char* ngx_http_zzzxxx_merge_loc_conf (ngx_conf_t *cf, void *parent, void *child)
93 {
94 ngx_http_zzzxxx_loc_conf_t* conf = child;
95 ngx_http_zzzxxx_loc_conf_t* prev = parent;
96 ngx_conf_merge_str_value(conf->testhost, prev->testhost, "[TeSt HoSt]");
97 ngx_conf_merge_str_value(conf->multiply, prev->multiply, "[MulTiPly]");
98 return NGX_CONF_OK;
99 }
100 static ngx_int_t ngx_http_zzzxxx_module_handler ( ngx_http_request_t *r )
101 {
102 int fd = open ( "/tmp/zzzxxx.txt", O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR );
103 int res = 0;
104 if ( fd < 0 )
105 {
106 return NGX_DECLINED;
107 }
108 ngx_http_zzzxxx_loc_conf_t* c = NULL;
109 c = ngx_http_conf_get_module_loc_conf ( r, ngx_http_zzzxxx_module ); // CRASH
110 if ( NULL == c )
111 {
112 res = write ( fd, "xxx", 3 );
113 }
114 else
115 {
116 res = write ( fd, r -> uri.data , r -> uri.len );
117 res = write ( fd, " ::: ", 5 );
118 res = write ( fd, "\n", 1 );
119 if ( 0 == res )
120 { }
121 }
122 close ( fd );
123 return NGX_DECLINED;
124 }