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