Mercurial > hg > nginx-quic
annotate src/http/modules/perl/ngx_http_perl_module.c @ 3572:b7c4d96cd61c stable-0.7
bump version
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 04 Jun 2010 17:38:59 +0000 |
parents | f419516d8e6e |
children | 724e5cd44164 |
rev | line source |
---|---|
599 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 #include <ngx_http_perl_module.h> | |
11 | |
12 | |
13 typedef struct { | |
14 PerlInterpreter *perl; | |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
15 HV *nginx; |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
16 ngx_array_t *modules; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
17 ngx_array_t *requires; |
599 | 18 } ngx_http_perl_main_conf_t; |
19 | |
20 | |
21 typedef struct { | |
22 SV *sub; | |
23 ngx_str_t handler; | |
24 } ngx_http_perl_loc_conf_t; | |
25 | |
26 | |
27 typedef struct { | |
28 SV *sub; | |
29 ngx_str_t handler; | |
30 } ngx_http_perl_variable_t; | |
31 | |
32 | |
653 | 33 typedef struct { |
34 SV *sv; | |
35 PerlInterpreter *perl; | |
36 } ngx_http_perl_cleanup_t; | |
37 | |
38 | |
617 | 39 #if (NGX_HTTP_SSI) |
599 | 40 static ngx_int_t ngx_http_perl_ssi(ngx_http_request_t *r, |
41 ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params); | |
617 | 42 #endif |
43 | |
599 | 44 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf, |
45 ngx_http_perl_main_conf_t *pmcf); | |
1069 | 46 static PerlInterpreter *ngx_http_perl_create_interpreter(ngx_conf_t *cf, |
47 ngx_http_perl_main_conf_t *pmcf); | |
653 | 48 static ngx_int_t ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, |
649 | 49 ngx_log_t *log); |
599 | 50 static ngx_int_t ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, |
1899
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
51 HV *nginx, SV *sub, SV **args, ngx_str_t *handler, ngx_str_t *rv); |
599 | 52 static void ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv); |
53 | |
54 static ngx_int_t ngx_http_perl_preconfiguration(ngx_conf_t *cf); | |
55 static void *ngx_http_perl_create_main_conf(ngx_conf_t *cf); | |
56 static char *ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf); | |
57 static void *ngx_http_perl_create_loc_conf(ngx_conf_t *cf); | |
58 static char *ngx_http_perl_merge_loc_conf(ngx_conf_t *cf, void *parent, | |
59 void *child); | |
60 static char *ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | |
61 static char *ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | |
872
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
62 |
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
63 #if (NGX_HAVE_PERL_MULTIPLICITY) |
599 | 64 static void ngx_http_perl_cleanup_perl(void *data); |
649 | 65 #endif |
599 | 66 |
1257 | 67 static ngx_int_t ngx_http_perl_init_worker(ngx_cycle_t *cycle); |
1221
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
68 static void ngx_http_perl_exit(ngx_cycle_t *cycle); |
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
69 |
599 | 70 |
71 static ngx_command_t ngx_http_perl_commands[] = { | |
72 | |
73 { ngx_string("perl_modules"), | |
74 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
75 ngx_conf_set_str_array_slot, |
599 | 76 NGX_HTTP_MAIN_CONF_OFFSET, |
77 offsetof(ngx_http_perl_main_conf_t, modules), | |
78 NULL }, | |
79 | |
80 { ngx_string("perl_require"), | |
81 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
82 ngx_conf_set_str_array_slot, |
599 | 83 NGX_HTTP_MAIN_CONF_OFFSET, |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
84 offsetof(ngx_http_perl_main_conf_t, requires), |
599 | 85 NULL }, |
86 | |
87 { ngx_string("perl"), | |
922
a5b9cdfe3e19
allow "perl" inside "limit_except"
Igor Sysoev <igor@sysoev.ru>
parents:
913
diff
changeset
|
88 NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1, |
599 | 89 ngx_http_perl, |
90 NGX_HTTP_LOC_CONF_OFFSET, | |
91 0, | |
92 NULL }, | |
93 | |
94 { ngx_string("perl_set"), | |
95 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE2, | |
96 ngx_http_perl_set, | |
97 NGX_HTTP_LOC_CONF_OFFSET, | |
98 0, | |
99 NULL }, | |
100 | |
101 ngx_null_command | |
102 }; | |
103 | |
104 | |
105 static ngx_http_module_t ngx_http_perl_module_ctx = { | |
106 ngx_http_perl_preconfiguration, /* preconfiguration */ | |
107 NULL, /* postconfiguration */ | |
108 | |
109 ngx_http_perl_create_main_conf, /* create main configuration */ | |
110 ngx_http_perl_init_main_conf, /* init main configuration */ | |
111 | |
112 NULL, /* create server configuration */ | |
113 NULL, /* merge server configuration */ | |
114 | |
115 ngx_http_perl_create_loc_conf, /* create location configuration */ | |
116 ngx_http_perl_merge_loc_conf /* merge location configuration */ | |
117 }; | |
118 | |
119 | |
120 ngx_module_t ngx_http_perl_module = { | |
121 NGX_MODULE_V1, | |
122 &ngx_http_perl_module_ctx, /* module context */ | |
123 ngx_http_perl_commands, /* module directives */ | |
124 NGX_HTTP_MODULE, /* module type */ | |
125 NULL, /* init master */ | |
126 NULL, /* init module */ | |
1257 | 127 ngx_http_perl_init_worker, /* init process */ |
599 | 128 NULL, /* init thread */ |
129 NULL, /* exit thread */ | |
130 NULL, /* exit process */ | |
1221
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
131 ngx_http_perl_exit, /* exit master */ |
599 | 132 NGX_MODULE_V1_PADDING |
133 }; | |
134 | |
135 | |
617 | 136 #if (NGX_HTTP_SSI) |
137 | |
599 | 138 #define NGX_HTTP_PERL_SSI_SUB 0 |
139 #define NGX_HTTP_PERL_SSI_ARG 1 | |
140 | |
141 | |
142 static ngx_http_ssi_param_t ngx_http_perl_ssi_params[] = { | |
143 { ngx_string("sub"), NGX_HTTP_PERL_SSI_SUB, 1, 0 }, | |
144 { ngx_string("arg"), NGX_HTTP_PERL_SSI_ARG, 0, 1 }, | |
145 { ngx_null_string, 0, 0, 0 } | |
146 }; | |
147 | |
148 static ngx_http_ssi_command_t ngx_http_perl_ssi_command = { | |
667 | 149 ngx_string("perl"), ngx_http_perl_ssi, ngx_http_perl_ssi_params, 0, 0, 1 |
599 | 150 }; |
151 | |
617 | 152 #endif |
153 | |
599 | 154 |
3442 | 155 static ngx_str_t ngx_null_name = ngx_null_string; |
156 static HV *nginx_stash; | |
681 | 157 |
2715 | 158 #if (NGX_HAVE_PERL_MULTIPLICITY) |
3442 | 159 static ngx_uint_t ngx_perl_term; |
160 #else | |
161 static PerlInterpreter *perl; | |
2715 | 162 #endif |
681 | 163 |
633 | 164 |
599 | 165 static void |
166 ngx_http_perl_xs_init(pTHX) | |
167 { | |
168 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__); | |
633 | 169 |
170 nginx_stash = gv_stashpv("nginx", TRUE); | |
599 | 171 } |
172 | |
173 | |
174 static ngx_int_t | |
175 ngx_http_perl_handler(ngx_http_request_t *r) | |
176 { | |
629 | 177 if (r->zero_in_uri) { |
178 return NGX_HTTP_NOT_FOUND; | |
179 } | |
180 | |
681 | 181 ngx_http_perl_handle_request(r); |
182 | |
183 return NGX_DONE; | |
629 | 184 } |
185 | |
186 | |
681 | 187 void |
629 | 188 ngx_http_perl_handle_request(ngx_http_request_t *r) |
189 { | |
681 | 190 SV *sub; |
599 | 191 ngx_int_t rc; |
681 | 192 ngx_str_t uri, args, *handler; |
599 | 193 ngx_http_perl_ctx_t *ctx; |
194 ngx_http_perl_loc_conf_t *plcf; | |
195 ngx_http_perl_main_conf_t *pmcf; | |
196 | |
197 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "perl handler"); | |
198 | |
199 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
200 | |
201 if (ctx == NULL) { | |
202 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t)); | |
203 if (ctx == NULL) { | |
681 | 204 ngx_http_finalize_request(r, NGX_ERROR); |
1025 | 205 return; |
599 | 206 } |
207 | |
208 ngx_http_set_ctx(r, ctx, ngx_http_perl_module); | |
209 } | |
210 | |
211 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module); | |
212 | |
213 { | |
214 | |
872
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
215 dTHXa(pmcf->perl); |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
216 PERL_SET_CONTEXT(pmcf->perl); |
599 | 217 |
681 | 218 if (ctx->next == NULL) { |
219 plcf = ngx_http_get_module_loc_conf(r, ngx_http_perl_module); | |
220 sub = plcf->sub; | |
221 handler = &plcf->handler; | |
599 | 222 |
681 | 223 } else { |
224 sub = ctx->next; | |
225 handler = &ngx_null_name; | |
226 ctx->next = NULL; | |
227 } | |
228 | |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
229 rc = ngx_http_perl_call_handler(aTHX_ r, pmcf->nginx, sub, NULL, handler, |
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
230 NULL); |
599 | 231 |
232 } | |
233 | |
1702
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
234 if (rc == NGX_DONE) { |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
235 return; |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
236 } |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
237 |
599 | 238 if (rc > 600) { |
239 rc = NGX_OK; | |
240 } | |
241 | |
242 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
243 "perl handler done: %i", rc); | |
244 | |
245 if (ctx->redirect_uri.len) { | |
246 uri = ctx->redirect_uri; | |
247 args = ctx->redirect_args; | |
629 | 248 |
249 } else { | |
250 uri.len = 0; | |
599 | 251 } |
252 | |
633 | 253 ctx->filename.data = NULL; |
599 | 254 ctx->redirect_uri.len = 0; |
255 | |
681 | 256 if (ctx->done || ctx->next) { |
257 return; | |
258 } | |
259 | |
599 | 260 if (uri.len) { |
629 | 261 ngx_http_internal_redirect(r, &uri, &args); |
262 return; | |
599 | 263 } |
264 | |
265 if (rc == NGX_OK || rc == NGX_HTTP_OK) { | |
629 | 266 ngx_http_send_special(r, NGX_HTTP_LAST); |
681 | 267 ctx->done = 1; |
599 | 268 } |
269 | |
629 | 270 ngx_http_finalize_request(r, rc); |
599 | 271 } |
272 | |
273 | |
1897 | 274 void |
911 | 275 ngx_http_perl_sleep_handler(ngx_http_request_t *r) |
276 { | |
913
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
277 ngx_event_t *wev; |
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
278 |
911 | 279 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
280 "perl sleep handler"); | |
281 | |
913
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
282 wev = r->connection->write; |
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
283 |
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
284 if (wev->timedout) { |
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
285 wev->timedout = 0; |
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
286 ngx_http_perl_handle_request(r); |
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
287 return; |
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
288 } |
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
289 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
290 if (ngx_handle_write_event(wev, 0) != NGX_OK) { |
913
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
291 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
90ce4d0e3241
fix ngx_http_perl_sleep_handler()
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
292 } |
911 | 293 } |
294 | |
295 | |
599 | 296 static ngx_int_t |
297 ngx_http_perl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
298 uintptr_t data) | |
299 { | |
300 ngx_http_perl_variable_t *pv = (ngx_http_perl_variable_t *) data; | |
301 | |
302 ngx_int_t rc; | |
303 ngx_str_t value; | |
304 ngx_http_perl_ctx_t *ctx; | |
305 ngx_http_perl_main_conf_t *pmcf; | |
306 | |
307 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
308 "perl variable handler"); | |
309 | |
310 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
311 | |
312 if (ctx == NULL) { | |
313 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t)); | |
314 if (ctx == NULL) { | |
315 return NGX_ERROR; | |
316 } | |
317 | |
318 ngx_http_set_ctx(r, ctx, ngx_http_perl_module); | |
872
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
319 } |
599 | 320 |
872
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
321 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module); |
599 | 322 |
323 value.data = NULL; | |
324 | |
325 { | |
326 | |
872
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
327 dTHXa(pmcf->perl); |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
328 PERL_SET_CONTEXT(pmcf->perl); |
599 | 329 |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
330 rc = ngx_http_perl_call_handler(aTHX_ r, pmcf->nginx, pv->sub, NULL, |
599 | 331 &pv->handler, &value); |
332 | |
333 } | |
334 | |
335 if (value.data) { | |
336 v->len = value.len; | |
337 v->valid = 1; | |
1565 | 338 v->no_cacheable = 0; |
599 | 339 v->not_found = 0; |
340 v->data = value.data; | |
341 | |
342 } else { | |
343 v->not_found = 1; | |
344 } | |
345 | |
633 | 346 ctx->filename.data = NULL; |
599 | 347 ctx->redirect_uri.len = 0; |
348 | |
871 | 349 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
350 "perl variable done"); | |
351 | |
599 | 352 return rc; |
353 } | |
354 | |
355 | |
617 | 356 #if (NGX_HTTP_SSI) |
357 | |
599 | 358 static ngx_int_t |
359 ngx_http_perl_ssi(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ssi_ctx, | |
360 ngx_str_t **params) | |
361 { | |
1899
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
362 SV *sv, **asv; |
599 | 363 ngx_int_t rc; |
1899
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
364 ngx_str_t *handler, **args; |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
365 ngx_uint_t i; |
599 | 366 ngx_http_perl_ctx_t *ctx; |
367 ngx_http_perl_main_conf_t *pmcf; | |
368 | |
369 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
370 "perl ssi handler"); | |
371 | |
372 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
373 | |
374 if (ctx == NULL) { | |
375 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t)); | |
376 if (ctx == NULL) { | |
377 return NGX_ERROR; | |
378 } | |
379 | |
380 ngx_http_set_ctx(r, ctx, ngx_http_perl_module); | |
381 } | |
382 | |
872
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
383 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module); |
599 | 384 |
385 ctx->ssi = ssi_ctx; | |
386 | |
387 handler = params[NGX_HTTP_PERL_SSI_SUB]; | |
388 handler->data[handler->len] = '\0'; | |
389 | |
390 { | |
391 | |
872
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
392 dTHXa(pmcf->perl); |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
393 PERL_SET_CONTEXT(pmcf->perl); |
599 | 394 |
651 | 395 #if 0 |
396 | |
397 /* the code is disabled to force the precompiled perl code using only */ | |
398 | |
399 ngx_http_perl_eval_anon_sub(aTHX_ handler, &sv); | |
400 | |
401 if (sv == &PL_sv_undef) { | |
402 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
403 "eval_pv(\"%V\") failed", handler); | |
404 return NGX_ERROR; | |
405 } | |
406 | |
407 if (sv == NULL) { | |
408 sv = newSVpvn((char *) handler->data, handler->len); | |
409 } | |
410 | |
411 #endif | |
412 | |
599 | 413 sv = newSVpvn((char *) handler->data, handler->len); |
414 | |
1899
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
415 args = ¶ms[NGX_HTTP_PERL_SSI_ARG]; |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
416 |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
417 if (args) { |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
418 |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
419 for (i = 0; args[i]; i++) { /* void */ } |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
420 |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
421 asv = ngx_pcalloc(r->pool, (i + 1) * sizeof(SV *)); |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
422 |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
423 if (asv == NULL) { |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
424 SvREFCNT_dec(sv); |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
425 return NGX_ERROR; |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
426 } |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
427 |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
428 asv[0] = (SV *) i; |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
429 |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
430 for (i = 0; args[i]; i++) { |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
431 asv[i + 1] = newSVpvn((char *) args[i]->data, args[i]->len); |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
432 } |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
433 |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
434 } else { |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
435 asv = NULL; |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
436 } |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
437 |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
438 rc = ngx_http_perl_call_handler(aTHX_ r, pmcf->nginx, sv, asv, handler, |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
439 NULL); |
599 | 440 |
441 SvREFCNT_dec(sv); | |
442 | |
443 } | |
444 | |
633 | 445 ctx->filename.data = NULL; |
599 | 446 ctx->redirect_uri.len = 0; |
447 ctx->ssi = NULL; | |
448 | |
871 | 449 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "perl ssi done"); |
450 | |
599 | 451 return rc; |
452 } | |
453 | |
617 | 454 #endif |
455 | |
599 | 456 |
457 static char * | |
458 ngx_http_perl_init_interpreter(ngx_conf_t *cf, ngx_http_perl_main_conf_t *pmcf) | |
459 { | |
3442 | 460 ngx_str_t *m; |
461 ngx_uint_t i; | |
872
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
462 #if (NGX_HAVE_PERL_MULTIPLICITY) |
3442 | 463 ngx_pool_cleanup_t *cln; |
599 | 464 |
465 cln = ngx_pool_cleanup_add(cf->pool, 0); | |
466 if (cln == NULL) { | |
467 return NGX_CONF_ERROR; | |
468 } | |
469 | |
649 | 470 #endif |
471 | |
599 | 472 #ifdef NGX_PERL_MODULES |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
473 if (pmcf->modules == NGX_CONF_UNSET_PTR) { |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
474 |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
475 pmcf->modules = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t)); |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
476 if (pmcf->modules == NULL) { |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
477 return NGX_CONF_ERROR; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
478 } |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
479 |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
480 m = ngx_array_push(pmcf->modules); |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
481 if (m == NULL) { |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
482 return NGX_CONF_ERROR; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
483 } |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
484 |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
485 m->len = sizeof(NGX_PERL_MODULES) - 1; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
486 m->data = NGX_PERL_MODULES; |
599 | 487 } |
488 #endif | |
489 | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
490 if (pmcf->modules != NGX_CONF_UNSET_PTR) { |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
491 m = pmcf->modules->elts; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
492 for (i = 0; i < pmcf->modules->nelts; i++) { |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
493 if (ngx_conf_full_name(cf->cycle, &m[i], 0) != NGX_OK) { |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
494 return NGX_CONF_ERROR; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
495 } |
639 | 496 } |
629 | 497 } |
498 | |
872
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
499 #if !(NGX_HAVE_PERL_MULTIPLICITY) |
649 | 500 |
501 if (perl) { | |
1165 | 502 |
503 if (ngx_set_environment(cf->cycle, NULL) == NULL) { | |
504 return NGX_CONF_ERROR; | |
505 } | |
506 | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
507 if (ngx_http_perl_run_requires(aTHX_ pmcf->requires, cf->log) |
653 | 508 != NGX_OK) |
509 { | |
649 | 510 return NGX_CONF_ERROR; |
511 } | |
512 | |
513 pmcf->perl = perl; | |
1163
8288459f15c9
set nginx_stash after reconfiguration in single interpreter perl
Igor Sysoev <igor@sysoev.ru>
parents:
1069
diff
changeset
|
514 pmcf->nginx = nginx_stash; |
649 | 515 |
516 return NGX_CONF_OK; | |
517 } | |
518 | |
519 #endif | |
520 | |
1221
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
521 if (nginx_stash == NULL) { |
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
522 PERL_SYS_INIT(&ngx_argc, &ngx_argv); |
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
523 } |
599 | 524 |
1069 | 525 pmcf->perl = ngx_http_perl_create_interpreter(cf, pmcf); |
599 | 526 |
527 if (pmcf->perl == NULL) { | |
528 return NGX_CONF_ERROR; | |
529 } | |
530 | |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
531 pmcf->nginx = nginx_stash; |
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
532 |
872
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
533 #if (NGX_HAVE_PERL_MULTIPLICITY) |
649 | 534 |
599 | 535 cln->handler = ngx_http_perl_cleanup_perl; |
536 cln->data = pmcf->perl; | |
537 | |
649 | 538 #else |
539 | |
540 perl = pmcf->perl; | |
541 | |
542 #endif | |
543 | |
599 | 544 return NGX_CONF_OK; |
545 } | |
546 | |
547 | |
548 static PerlInterpreter * | |
1069 | 549 ngx_http_perl_create_interpreter(ngx_conf_t *cf, |
550 ngx_http_perl_main_conf_t *pmcf) | |
599 | 551 { |
552 int n; | |
775 | 553 STRLEN len; |
554 SV *sv; | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
555 char *ver, **embedding; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
556 ngx_str_t *m; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
557 ngx_uint_t i; |
599 | 558 PerlInterpreter *perl; |
559 | |
1069 | 560 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, "create perl interpreter"); |
561 | |
562 if (ngx_set_environment(cf->cycle, NULL) == NULL) { | |
563 return NULL; | |
564 } | |
599 | 565 |
566 perl = perl_alloc(); | |
567 if (perl == NULL) { | |
1069 | 568 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, "perl_alloc() failed"); |
599 | 569 return NULL; |
570 } | |
571 | |
572 { | |
573 | |
574 dTHXa(perl); | |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
575 PERL_SET_CONTEXT(perl); |
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
576 |
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
577 perl_construct(perl); |
599 | 578 |
579 #ifdef PERL_EXIT_DESTRUCT_END | |
580 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; | |
581 #endif | |
582 | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
583 n = (pmcf->modules != NGX_CONF_UNSET_PTR) ? pmcf->modules->nelts * 2 : 0; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
584 |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
585 embedding = ngx_palloc(cf->pool, (4 + n) * sizeof(char *)); |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
586 if (embedding == NULL) { |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
587 goto fail; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
588 } |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
589 |
599 | 590 embedding[0] = ""; |
591 | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
592 if (n++) { |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
593 m = pmcf->modules->elts; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
594 for (i = 0; i < pmcf->modules->nelts; i++) { |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
595 embedding[2 * i + 1] = "-I"; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
596 embedding[2 * i + 2] = (char *) m[i].data; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
597 } |
599 | 598 } |
599 | |
600 embedding[n++] = "-Mnginx"; | |
601 embedding[n++] = "-e"; | |
602 embedding[n++] = "0"; | |
603 | |
604 n = perl_parse(perl, ngx_http_perl_xs_init, n, embedding, NULL); | |
605 | |
606 if (n != 0) { | |
1069 | 607 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, "perl_parse() failed: %d", n); |
599 | 608 goto fail; |
609 } | |
610 | |
775 | 611 sv = get_sv("nginx::VERSION", FALSE); |
612 ver = SvPV(sv, len); | |
613 | |
614 if (ngx_strcmp(ver, NGINX_VERSION) != 0) { | |
1069 | 615 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, |
775 | 616 "version " NGINX_VERSION " of nginx.pm is required, " |
617 "but %s was found", ver); | |
618 goto fail; | |
619 } | |
620 | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
621 if (ngx_http_perl_run_requires(aTHX_ pmcf->requires, cf->log) != NGX_OK) { |
649 | 622 goto fail; |
599 | 623 } |
624 | |
625 } | |
626 | |
627 return perl; | |
628 | |
629 fail: | |
630 | |
631 (void) perl_destruct(perl); | |
632 | |
633 perl_free(perl); | |
634 | |
635 return NULL; | |
636 } | |
637 | |
638 | |
649 | 639 static ngx_int_t |
653 | 640 ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, ngx_log_t *log) |
649 | 641 { |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
642 u_char *err; |
649 | 643 STRLEN len; |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
644 ngx_str_t *script; |
649 | 645 ngx_uint_t i; |
646 | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
647 if (requires == NGX_CONF_UNSET_PTR) { |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
648 return NGX_OK; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
649 } |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
650 |
649 | 651 script = requires->elts; |
652 for (i = 0; i < requires->nelts; i++) { | |
653 | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
654 require_pv((char *) script[i].data); |
649 | 655 |
656 if (SvTRUE(ERRSV)) { | |
657 | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
658 err = (u_char *) SvPV(ERRSV, len); |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
659 while (--len && (err[len] == CR || err[len] == LF)) { /* void */ } |
649 | 660 |
661 ngx_log_error(NGX_LOG_EMERG, log, 0, | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
662 "require_pv(\"%s\") failed: \"%*s\"", |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
663 script[i].data, len + 1, err); |
649 | 664 |
665 return NGX_ERROR; | |
666 } | |
667 } | |
668 | |
669 return NGX_OK; | |
670 } | |
671 | |
672 | |
599 | 673 static ngx_int_t |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
674 ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, HV *nginx, SV *sub, |
1899
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
675 SV **args, ngx_str_t *handler, ngx_str_t *rv) |
599 | 676 { |
1702
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
677 SV *sv; |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
678 int n, status; |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
679 char *line; |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
680 u_char *err; |
1702
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
681 STRLEN len, n_a; |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
682 ngx_uint_t i; |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
683 ngx_connection_t *c; |
599 | 684 |
685 dSP; | |
686 | |
687 status = 0; | |
688 | |
689 ENTER; | |
690 SAVETMPS; | |
691 | |
692 PUSHMARK(sp); | |
693 | |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
694 sv = sv_2mortal(sv_bless(newRV_noinc(newSViv(PTR2IV(r))), nginx)); |
599 | 695 XPUSHs(sv); |
696 | |
697 if (args) { | |
1940
6a4c74bea81c
fix building on 64-bit platforms broken in r1900
Igor Sysoev <igor@sysoev.ru>
parents:
1899
diff
changeset
|
698 EXTEND(sp, (intptr_t) args[0]); |
599 | 699 |
1899
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
700 for (i = 1; i <= (ngx_uint_t) args[0]; i++) { |
d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
Igor Sysoev <igor@sysoev.ru>
parents:
1897
diff
changeset
|
701 PUSHs(sv_2mortal(args[i])); |
599 | 702 } |
703 } | |
704 | |
705 PUTBACK; | |
706 | |
1702
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
707 c = r->connection; |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
708 |
599 | 709 n = call_sv(sub, G_EVAL); |
710 | |
711 SPAGAIN; | |
712 | |
1702
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
713 if (c->destroyed) { |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
714 PUTBACK; |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
715 |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
716 FREETMPS; |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
717 LEAVE; |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
718 |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
719 return NGX_DONE; |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
720 } |
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
721 |
599 | 722 if (n) { |
723 if (rv == NULL) { | |
724 status = POPi; | |
725 | |
1702
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
726 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
599 | 727 "call_sv: %d", status); |
728 | |
729 } else { | |
619 | 730 line = SvPVx(POPs, n_a); |
599 | 731 rv->len = n_a; |
732 | |
2049 | 733 rv->data = ngx_pnalloc(r->pool, n_a); |
599 | 734 if (rv->data == NULL) { |
735 return NGX_ERROR; | |
736 } | |
737 | |
738 ngx_memcpy(rv->data, line, n_a); | |
739 } | |
740 } | |
741 | |
742 PUTBACK; | |
743 | |
744 FREETMPS; | |
745 LEAVE; | |
746 | |
747 /* check $@ */ | |
748 | |
749 if (SvTRUE(ERRSV)) { | |
750 | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
751 err = (u_char *) SvPV(ERRSV, len); |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
752 while (--len && (err[len] == CR || err[len] == LF)) { /* void */ } |
599 | 753 |
1702
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
754 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
755 "call_sv(\"%V\") failed: \"%*s\"", handler, len + 1, err); |
599 | 756 |
757 if (rv) { | |
758 return NGX_ERROR; | |
759 } | |
760 | |
761 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
762 } | |
763 | |
764 if (n != 1) { | |
1702
86bb52e28ce0
fix segfault when $r->has_request_body() is called with ready body
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
765 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
599 | 766 "call_sv(\"%V\") returned %d results", handler, n); |
767 status = NGX_OK; | |
768 } | |
769 | |
770 if (rv) { | |
771 return NGX_OK; | |
772 } | |
773 | |
774 return (ngx_int_t) status; | |
775 } | |
776 | |
777 | |
778 static void | |
779 ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv) | |
780 { | |
623 | 781 u_char *p; |
782 | |
783 for (p = handler->data; *p; p++) { | |
784 if (*p != ' ' && *p != '\t' && *p != CR && *p != LF) { | |
785 break; | |
786 } | |
787 } | |
788 | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
789 if (ngx_strncmp(p, "sub ", 4) == 0 |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
790 || ngx_strncmp(p, "sub{", 4) == 0 |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
791 || ngx_strncmp(p, "use ", 4) == 0) |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
792 { |
623 | 793 *sv = eval_pv((char *) p, FALSE); |
874 | 794 |
795 /* eval_pv() does not set ERRSV on failure */ | |
796 | |
599 | 797 return; |
798 } | |
799 | |
800 *sv = NULL; | |
801 } | |
802 | |
803 | |
804 static void * | |
805 ngx_http_perl_create_main_conf(ngx_conf_t *cf) | |
806 { | |
807 ngx_http_perl_main_conf_t *pmcf; | |
808 | |
809 pmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_perl_main_conf_t)); | |
810 if (pmcf == NULL) { | |
3237
2efa8d2fcde1
merge r2903, r2911, r2912, r3002:
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
811 return NULL; |
599 | 812 } |
813 | |
3239
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
814 pmcf->modules = NGX_CONF_UNSET_PTR; |
8254055b6693
merge r2972, r2994, r3133, r3142, r3143, r3174, r3175, r3176:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
815 pmcf->requires = NGX_CONF_UNSET_PTR; |
599 | 816 |
817 return pmcf; | |
818 } | |
819 | |
820 | |
821 static char * | |
822 ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf) | |
823 { | |
824 ngx_http_perl_main_conf_t *pmcf = conf; | |
825 | |
826 if (pmcf->perl == NULL) { | |
827 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { | |
828 return NGX_CONF_ERROR; | |
829 } | |
830 } | |
831 | |
832 return NGX_CONF_OK; | |
833 } | |
834 | |
835 | |
872
1c4a5b3f9110
Axe several perl interpreter instances: they may be useful in currently
Igor Sysoev <igor@sysoev.ru>
parents:
871
diff
changeset
|
836 #if (NGX_HAVE_PERL_MULTIPLICITY) |
649 | 837 |
599 | 838 static void |
839 ngx_http_perl_cleanup_perl(void *data) | |
840 { | |
649 | 841 PerlInterpreter *perl = data; |
599 | 842 |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
843 PERL_SET_CONTEXT(perl); |
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
844 |
599 | 845 (void) perl_destruct(perl); |
846 | |
847 perl_free(perl); | |
2715 | 848 |
849 if (ngx_perl_term) { | |
850 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, "perl term"); | |
851 | |
852 PERL_SYS_TERM(); | |
853 } | |
599 | 854 } |
855 | |
649 | 856 #endif |
857 | |
858 | |
599 | 859 static ngx_int_t |
860 ngx_http_perl_preconfiguration(ngx_conf_t *cf) | |
861 { | |
617 | 862 #if (NGX_HTTP_SSI) |
599 | 863 ngx_int_t rc; |
864 ngx_http_ssi_main_conf_t *smcf; | |
865 | |
866 smcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_ssi_filter_module); | |
867 | |
868 rc = ngx_hash_add_key(&smcf->commands, &ngx_http_perl_ssi_command.name, | |
869 &ngx_http_perl_ssi_command, NGX_HASH_READONLY_KEY); | |
870 | |
871 if (rc != NGX_OK) { | |
872 if (rc == NGX_BUSY) { | |
873 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
874 "conflicting SSI command \"%V\"", | |
875 &ngx_http_perl_ssi_command.name); | |
876 } | |
877 | |
878 return NGX_ERROR; | |
879 } | |
617 | 880 #endif |
599 | 881 |
882 return NGX_OK; | |
883 } | |
884 | |
885 | |
886 static void * | |
887 ngx_http_perl_create_loc_conf(ngx_conf_t *cf) | |
888 { | |
889 ngx_http_perl_loc_conf_t *plcf; | |
890 | |
891 plcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_perl_loc_conf_t)); | |
892 if (plcf == NULL) { | |
3237
2efa8d2fcde1
merge r2903, r2911, r2912, r3002:
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
893 return NULL; |
599 | 894 } |
895 | |
896 /* | |
897 * set by ngx_pcalloc(): | |
898 * | |
899 * plcf->handler = { 0, NULL }; | |
900 */ | |
901 | |
902 return plcf; | |
903 } | |
904 | |
905 | |
906 static char * | |
907 ngx_http_perl_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
908 { | |
909 ngx_http_perl_loc_conf_t *prev = parent; | |
910 ngx_http_perl_loc_conf_t *conf = child; | |
911 | |
912 if (conf->sub == NULL) { | |
913 conf->sub = prev->sub; | |
914 conf->handler = prev->handler; | |
915 } | |
916 | |
917 return NGX_CONF_OK; | |
918 } | |
919 | |
920 | |
921 static char * | |
922 ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
923 { | |
924 ngx_http_perl_loc_conf_t *plcf = conf; | |
925 | |
926 ngx_str_t *value; | |
927 ngx_http_core_loc_conf_t *clcf; | |
928 ngx_http_perl_main_conf_t *pmcf; | |
929 | |
930 value = cf->args->elts; | |
931 | |
932 if (plcf->handler.data) { | |
933 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
934 "duplicate perl handler \"%V\"", &value[1]); | |
935 return NGX_CONF_ERROR; | |
936 } | |
937 | |
938 pmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_perl_module); | |
939 | |
940 if (pmcf->perl == NULL) { | |
941 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { | |
942 return NGX_CONF_ERROR; | |
943 } | |
944 } | |
945 | |
946 plcf->handler = value[1]; | |
947 | |
948 { | |
949 | |
950 dTHXa(pmcf->perl); | |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
951 PERL_SET_CONTEXT(pmcf->perl); |
599 | 952 |
953 ngx_http_perl_eval_anon_sub(aTHX_ &value[1], &plcf->sub); | |
954 | |
955 if (plcf->sub == &PL_sv_undef) { | |
956 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, | |
957 "eval_pv(\"%V\") failed", &value[1]); | |
958 return NGX_CONF_ERROR; | |
959 } | |
960 | |
961 if (plcf->sub == NULL) { | |
962 plcf->sub = newSVpvn((char *) value[1].data, value[1].len); | |
963 } | |
964 | |
965 } | |
966 | |
967 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
968 clcf->handler = ngx_http_perl_handler; | |
969 | |
970 return NGX_CONF_OK; | |
971 } | |
972 | |
973 | |
974 static char * | |
975 ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
976 { | |
977 ngx_int_t index; | |
978 ngx_str_t *value; | |
979 ngx_http_variable_t *v; | |
980 ngx_http_perl_variable_t *pv; | |
981 ngx_http_perl_main_conf_t *pmcf; | |
982 | |
983 value = cf->args->elts; | |
984 | |
985 if (value[1].data[0] != '$') { | |
986 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
987 "invalid variable name \"%V\"", &value[1]); | |
988 return NGX_CONF_ERROR; | |
989 } | |
990 | |
991 value[1].len--; | |
992 value[1].data++; | |
993 | |
1565 | 994 v = ngx_http_add_variable(cf, &value[1], NGX_HTTP_VAR_CHANGEABLE); |
599 | 995 if (v == NULL) { |
996 return NGX_CONF_ERROR; | |
997 } | |
998 | |
999 pv = ngx_palloc(cf->pool, sizeof(ngx_http_perl_variable_t)); | |
1000 if (pv == NULL) { | |
1001 return NGX_CONF_ERROR; | |
1002 } | |
1003 | |
1004 index = ngx_http_get_variable_index(cf, &value[1]); | |
1005 if (index == NGX_ERROR) { | |
1006 return NGX_CONF_ERROR; | |
1007 } | |
1008 | |
1009 pmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_perl_module); | |
1010 | |
1011 if (pmcf->perl == NULL) { | |
1012 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { | |
1013 return NGX_CONF_ERROR; | |
1014 } | |
1015 } | |
1016 | |
1017 pv->handler = value[2]; | |
1018 | |
1019 { | |
1020 | |
1021 dTHXa(pmcf->perl); | |
873
f92ad15c2db1
fix segfaults in future workers those will use old configuration,
Igor Sysoev <igor@sysoev.ru>
parents:
872
diff
changeset
|
1022 PERL_SET_CONTEXT(pmcf->perl); |
599 | 1023 |
1024 ngx_http_perl_eval_anon_sub(aTHX_ &value[2], &pv->sub); | |
1025 | |
1026 if (pv->sub == &PL_sv_undef) { | |
1027 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, | |
1028 "eval_pv(\"%V\") failed", &value[2]); | |
1029 return NGX_CONF_ERROR; | |
1030 } | |
1031 | |
1032 if (pv->sub == NULL) { | |
1033 pv->sub = newSVpvn((char *) value[2].data, value[2].len); | |
1034 } | |
1035 | |
1036 } | |
1037 | |
637 | 1038 v->get_handler = ngx_http_perl_variable; |
599 | 1039 v->data = (uintptr_t) pv; |
1040 | |
1041 return NGX_CONF_OK; | |
1042 } | |
1221
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
1043 |
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
1044 |
1257 | 1045 static ngx_int_t |
1046 ngx_http_perl_init_worker(ngx_cycle_t *cycle) | |
1047 { | |
1258
5076d97b9cf0
fix building on threaded or multiplicity interpreter perl,
Igor Sysoev <igor@sysoev.ru>
parents:
1257
diff
changeset
|
1048 ngx_http_perl_main_conf_t *pmcf; |
5076d97b9cf0
fix building on threaded or multiplicity interpreter perl,
Igor Sysoev <igor@sysoev.ru>
parents:
1257
diff
changeset
|
1049 |
5076d97b9cf0
fix building on threaded or multiplicity interpreter perl,
Igor Sysoev <igor@sysoev.ru>
parents:
1257
diff
changeset
|
1050 pmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_perl_module); |
5076d97b9cf0
fix building on threaded or multiplicity interpreter perl,
Igor Sysoev <igor@sysoev.ru>
parents:
1257
diff
changeset
|
1051 |
2713
b4d8aef4a1ad
fix segfault if no http section is defined in confguraiton,
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
1052 if (pmcf) { |
b4d8aef4a1ad
fix segfault if no http section is defined in confguraiton,
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
1053 dTHXa(pmcf->perl); |
b4d8aef4a1ad
fix segfault if no http section is defined in confguraiton,
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
1054 PERL_SET_CONTEXT(pmcf->perl); |
1258
5076d97b9cf0
fix building on threaded or multiplicity interpreter perl,
Igor Sysoev <igor@sysoev.ru>
parents:
1257
diff
changeset
|
1055 |
2713
b4d8aef4a1ad
fix segfault if no http section is defined in confguraiton,
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
1056 /* set worker's $$ */ |
1257 | 1057 |
2713
b4d8aef4a1ad
fix segfault if no http section is defined in confguraiton,
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
1058 sv_setiv(GvSV(gv_fetchpv("$", TRUE, SVt_PV)), (I32) ngx_pid); |
1258
5076d97b9cf0
fix building on threaded or multiplicity interpreter perl,
Igor Sysoev <igor@sysoev.ru>
parents:
1257
diff
changeset
|
1059 } |
5076d97b9cf0
fix building on threaded or multiplicity interpreter perl,
Igor Sysoev <igor@sysoev.ru>
parents:
1257
diff
changeset
|
1060 |
1257 | 1061 return NGX_OK; |
1062 } | |
1063 | |
1941 | 1064 |
1221
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
1065 static void |
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
1066 ngx_http_perl_exit(ngx_cycle_t *cycle) |
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
1067 { |
2715 | 1068 #if (NGX_HAVE_PERL_MULTIPLICITY) |
1069 | |
3442 | 1070 /* |
1071 * the master exit hook is run before global pool cleanup, | |
1072 * therefore just set flag here | |
1073 */ | |
1074 | |
2715 | 1075 ngx_perl_term = 1; |
1076 | |
1077 #else | |
1946
171a283af56b
some perl builds require my_perl for PERL_SYS_TERM()
Igor Sysoev <igor@sysoev.ru>
parents:
1941
diff
changeset
|
1078 |
3442 | 1079 if (nginx_stash) { |
2715 | 1080 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cycle->log, 0, "perl term"); |
1081 | |
3442 | 1082 (void) perl_destruct(perl); |
2715 | 1083 |
3442 | 1084 perl_free(perl); |
1946
171a283af56b
some perl builds require my_perl for PERL_SYS_TERM()
Igor Sysoev <igor@sysoev.ru>
parents:
1941
diff
changeset
|
1085 |
2714
4dd1773990db
fix segfault on exit if no http section is defined in confguraiton,
Igor Sysoev <igor@sysoev.ru>
parents:
2713
diff
changeset
|
1086 PERL_SYS_TERM(); |
1946
171a283af56b
some perl builds require my_perl for PERL_SYS_TERM()
Igor Sysoev <igor@sysoev.ru>
parents:
1941
diff
changeset
|
1087 } |
2715 | 1088 |
1089 #endif | |
1221
aa653367028e
PERL_SYS_TERM() should be called once on exit only, this fixes the message
Igor Sysoev <igor@sysoev.ru>
parents:
1165
diff
changeset
|
1090 } |